Skip to content

Commit

Permalink
fix: close watcher if it's disabled (#18521)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 30, 2024
1 parent 3a46f97 commit 85bd0e9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,17 @@ export async function _createServer(

const watcher = chokidar.watch(
// config file dependencies and env file might be outside of root
[
root,
...config.configFileDependencies,
...getEnvFilesForMode(config.mode, config.envDir),
// Watch the public directory explicitly because it might be outside
// of the root directory.
...(publicDir && publicFiles ? [publicDir] : []),
],
// eslint-disable-next-line eqeqeq -- null means disabled
serverConfig.watch === null
? []
: [
root,
...config.configFileDependencies,
...getEnvFilesForMode(config.mode, config.envDir),
// Watch the public directory explicitly because it might be outside
// of the root directory.
...(publicDir && publicFiles ? [publicDir] : []),
],
resolvedWatchOptions,
)
// If watch is turned off, patch `.add()` as a noop to prevent programmatically
Expand All @@ -486,6 +489,7 @@ export async function _createServer(
watcher.add = function () {
return this
}
await watcher.close()
}

const environments: Record<string, DevEnvironment> = {}
Expand Down

0 comments on commit 85bd0e9

Please sign in to comment.