Skip to content

Commit

Permalink
docs: update working solutions to watch a package inside node_modules/
Browse files Browse the repository at this point in the history
The current `server.watch` docs aren't accurate and the solution
proposed just doesn't work. See vitejs#8619

There is a different workaround in the issue using a custom Vite plugin
if you're using the Vite dev server, vitejs#8619 (comment)
  • Loading branch information
MadLittleMods committed May 27, 2023
1 parent a460a2b commit 57193ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
6 changes: 6 additions & 0 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ 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.
Expand Down
29 changes: 19 additions & 10 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,32 @@ 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/**'],
plugins: [
{
name: 'watch-node-modules',
configureServer: (server: ViteDevServer): void => {
server.watcher.options = {
...server.watcher.options,
ignored: [/node_modules\/(?!my-package-name).*/, '**/.git/**'],
}
},
},
},
// 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'],
},
],
})
```

:::

::: 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.
Expand Down

0 comments on commit 57193ec

Please sign in to comment.