Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring outDir in Chokidar watcher introduced regression in >=5.1.0, not entirely fixed by #15979 #16248

Closed
7 tasks done
jedso opened this issue Mar 24, 2024 · 1 comment · Fixed by #16453
Closed
7 tasks done
Labels
p2-to-be-discussed Enhancement under consideration (priority)

Comments

@jedso
Copy link

jedso commented Mar 24, 2024

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:

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

  1. Run npm run build (the script has --watch appended to vite build)
  2. Edit outDir/styles.scss and observe how saved changes do not trigger a re-build
  3. Downgrade Vite to pre-5.1.0 (e.g. npm install -D [email protected])
  4. Run npm run build again
  5. Observe how saved changes to outDir/styles.scss trigger 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.4

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Mar 24, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added the p2-to-be-discussed Enhancement under consideration (priority) label Apr 17, 2024
@github-project-automation github-project-automation bot moved this to Discussing in Team Board Apr 17, 2024
@sapphi-red sapphi-red moved this from Discussing to P2 - 4 in Team Board Apr 17, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-to-be-discussed Enhancement under consideration (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants