Skip to content

Commit

Permalink
fix(hmr): make watcher ignore build.outDir (#15326)
Browse files Browse the repository at this point in the history
  • Loading branch information
NozomuIkuta committed Jan 9, 2024
1 parent 8ccf722 commit 2836276
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default defineConfig({

File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar#api).

The Vite server watcher watches the `root` and skips the `.git/` and `node_modules/` directories by default. When updating a watched file, Vite will apply HMR and update the page only if needed.
The Vite server watcher watches the `root` and skips the `.git/`, `node_modules/`, and Vite's `cacheDir` and `build.outDir` directories by default. When updating a watched file, Vite will apply HMR and update the page only if needed.

If set to `null`, no files will be watched. `server.watcher` will provide a compatible event emitter, but calling `add` or `unwatch` will have no effect.

Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/node/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter } from 'node:events'
import path from 'node:path'
import glob from 'fast-glob'
import type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
import { arraify } from './utils'
Expand All @@ -16,6 +17,7 @@ export function resolveChokidarOptions(
'**/node_modules/**',
'**/test-results/**', // Playwright
glob.escapePath(config.cacheDir) + '/**',
glob.escapePath(path.resolve(config.root, config.build.outDir)) + '/**',
...arraify(ignored),
],
ignoreInitial: true,
Expand Down

0 comments on commit 2836276

Please sign in to comment.