From 1d263d39d32838cf5b77eeb44426ae81e969309c Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 20 Feb 2024 18:47:45 +0800 Subject: [PATCH] fix(watch): build watch fails when outDir is empty string (#15979) --- packages/vite/src/node/watch.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index a1718ffb25166a..9c9972bdd3a471 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -9,17 +9,22 @@ export function resolveChokidarOptions( config: ResolvedConfig, options: WatchOptions | undefined, ): WatchOptions { - const { ignored = [], ...otherOptions } = options ?? {} + const { ignored: ignoredList, ...otherOptions } = options ?? {} + const ignored: WatchOptions['ignored'] = [ + '**/.git/**', + '**/node_modules/**', + '**/test-results/**', // Playwright + glob.escapePath(config.cacheDir) + '/**', + ...arraify(ignoredList || []), + ] + if (config.build.outDir) { + ignored.push( + glob.escapePath(path.resolve(config.root, config.build.outDir)) + '/**', + ) + } const resolvedWatchOptions: WatchOptions = { - ignored: [ - '**/.git/**', - '**/node_modules/**', - '**/test-results/**', // Playwright - glob.escapePath(config.cacheDir) + '/**', - glob.escapePath(path.resolve(config.root, config.build.outDir)) + '/**', - ...arraify(ignored), - ], + ignored, ignoreInitial: true, ignorePermissionErrors: true, ...otherOptions,