Copy server.watch
config option from vite.config.(ts|js)
to child vite server in development mode
#14298
+7
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
Issue
As my
react-router
-based (latest release version) project grew, I encountered the following error when runningreact-router
(as an Express.js app) in development mode:Output of `npm run dev`
Invistigation
undefined
value to the watch option of the Vite server, which enabled the watch mode: https://github.com/vitejs/vite/blob/bcc31449c0c4f852ccb1eedda1842bc7ded23d01/packages/vite/src/node/server/index.ts#L493undefeined
watch option falls back to an empty watch option, which causes starting the Vite server with default config: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/watch.ts#L57Vite
with thereactRouter()
plugin is trying to subscribe to all files in the project dir with some hard-coded exceptions: https://github.com/vitejs/vite/blob/bcc31449c0c4f852ccb1eedda1842bc7ded23d01/packages/vite/src/node/watch.ts#L58Solution
In my simple solution, I just copied the
server.watch
option from thevite.config.(ts|js)
config to the Vite server inside thereactRouter()
plugin to respect the project config within.My small fix solves this problem. Also, my fix sped up the development server startup time several times (from ~1 minute to ~10 seconds).
A project context
For the context, some files from my project can be relevant to the issue:
Content of `server.js`
Content of `vite.config.ts`
Content of `scripts/utilities/ignore-file.mjs`