-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Describe the bug
I have a legacy project migrated from Gulp where a Sass file lives within the same directory as the outDir. Since Vite version >=5.1.0 (specifically #15326), vite build --watch no longer re-builds upon changes to the source Sass file. This issue is closely related to the problem described in #15951, which was fixed by the following conditional check in #15979:
vite/packages/vite/src/node/watch.ts
Lines 20 to 24 in 6a07243
| if (config.build.outDir) { | |
| ignored.push( | |
| glob.escapePath(path.resolve(config.root, config.build.outDir)) + '/**', | |
| ) | |
| } |
The difference, in my case, is that outDir is not an empty string and instead is its own separate directory. The common thread between this issue and #15951 is that both projects have emptyOutDir set to false. My suggestion to fix my issue, while still solving the issue described in #15951, would be to test for emptyOutDir instead:
if (config.build.emptyOutDir) { ... }The thinking here is if the outDir is being emptied out for every build, there is no point watching for changes within. On the other hand, if the directory isn't being emptied, it is possible that source files may be present and need to be watched for. If there's agreement around this solution, I would be more than happy to open a PR with this change and update the docs.
Reproduction
https://stackblitz.com/edit/vitejs-vite-spjjif?file=vite.config.ts
Steps to reproduce
- Run
npm run build(the script has--watchappended tovite build) - Edit
outDir/styles.scssand observe how saved changes do not trigger a re-build - Downgrade Vite to pre-5.1.0 (e.g.
npm install -D vite@5.0.12) - Run
npm run buildagain - Observe how saved changes to
outDir/styles.scsstrigger a re-build
System Info
System:
OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (4) x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
Memory: 12.39 GB / 15.49 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
Binaries:
Node: 20.11.1 - /usr/bin/node
npm: 10.2.4 - /usr/bin/npm
npmPackages:
vite: ^5.2.4 => 5.2.4Used Package Manager
npm
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status