diff --git a/docs/config/build-options.md b/docs/config/build-options.md index 22306a7eabcc3b..2772537e549c4a 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -245,6 +245,13 @@ Limit for chunk size warnings (in kbs). It is compared against the uncompressed Set to `{}` to enable rollup watcher. This is mostly used in cases that involve build-only plugins or integrations processes. + +::: warning Watch a package inside `node_modules/` + +It's currently not possible to watch a package inside `node_modules/` until https://github.com/vitejs/vite/issues/8619 is resolved. There isn't a known workaround for Vite build yet. + +::: + ::: warning Using Vite on Windows Subsystem for Linux (WSL) 2 There are cases that file system watching does not work with WSL2. diff --git a/docs/config/server-options.md b/docs/config/server-options.md index ab0f1b261ddb7c..76e14cdec47b52 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -173,23 +173,35 @@ The error that appears in the Browser when the fallback happens can be ignored. File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar#api). -The Vite server watcher skips `.git/` and `node_modules/` directories by default. If you want to watch a package inside `node_modules/`, you can pass a negated glob pattern to `server.watch.ignored`. That is: +The Vite server watcher skips `.git/` and `node_modules/` directories by default. + +::: warning Watch a package inside `node_modules/` + +It's currently not possible to watch a package inside `node_modules/` until https://github.com/vitejs/vite/issues/8619 is resolved. + +You can work around this by adding the following to your `vite.config.js`: ```js export default defineConfig({ - server: { - watch: { - ignored: ['!**/node_modules/your-package-name/**'], - }, - }, - // The watched package must be excluded from optimization, - // so that it can appear in the dependency graph and trigger hot reload. - optimizeDeps: { - exclude: ['your-package-name'], - }, + plugins: [ + { + name: 'watch-node-modules', + configureServer: (server: ViteDevServer) : void => { + server.watcher.options = { + ...server.watcher.options, + ignored: [ + /node_modules\/(?!my-package-name).*/, + '**/.git/**', + ] + } + } + } + ] }) ``` +::: + ::: warning Using Vite on Windows Subsystem for Linux (WSL) 2 When running Vite on WSL2, file system watching does not work when a file is edited by Windows applications (non-WSL2 process). This is due to [a WSL2 limitation](https://github.com/microsoft/WSL/issues/4739). This also applies to running on Docker with a WSL2 backend.