-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Describe the bug
Under Vite 5, a plugin's buildStart doesn't run during vite optimize.
Under Vite 6 it does, as a side-effect of environment.init() being introduced in optimizeDeps().
And since vite optimize rather confusingly uses command === 'serve' here, plugins now have no way of knowing whether their buildStart is running in vite dev vs vite optimize.
As a result, plugins that want to manage a dev-time background task will launch that task during vite optimize and can cause node to refuse to exit, since they think they are supposed to keep serving content.
Reproduction
https://stackblitz.com/edit/vitejs-vite-ncfab2z9?file=vite.config.js
Steps to reproduce
The linked stackbliz has a minimal reproduction. Run vite optimize and observe that the process refuses to exit.
You can repeat the same vite.config.js on Vite 5.x and observe that vite optimize no longer hangs.
System Info
N/AUsed Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.