From 2836276dc0e132c4d64dc4c08fc730058406f2c0 Mon Sep 17 00:00:00 2001 From: Nozomu Ikuta <16436160+NozomuIkuta@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:31:22 +0900 Subject: [PATCH] fix(hmr): make watcher ignore build.outDir (#15326) --- docs/config/server-options.md | 2 +- packages/vite/src/node/watch.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/config/server-options.md b/docs/config/server-options.md index 9efdd443fea150..b1c23cb09000b1 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -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. diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index c5dc879ac56a48..e04f6a62769b78 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -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' @@ -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,