From acfa394e827e9dd2cc011b8cbcc1dc3bcb9e75e1 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 20 Feb 2024 17:03:12 +0800 Subject: [PATCH 1/3] fix(watch): build watch fails when outDir is empty string --- packages/vite/src/node/watch.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index a1718ffb25166a..ac20749737265e 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -10,6 +10,12 @@ export function resolveChokidarOptions( options: WatchOptions | undefined, ): WatchOptions { const { ignored = [], ...otherOptions } = options ?? {} + const arraifyIgnored = arraify(ignored) + if (config.build.outDir) { + arraifyIgnored.push( + glob.escapePath(path.resolve(config.root, config.build.outDir)), + ) + } const resolvedWatchOptions: WatchOptions = { ignored: [ @@ -17,8 +23,7 @@ export function resolveChokidarOptions( '**/node_modules/**', '**/test-results/**', // Playwright glob.escapePath(config.cacheDir) + '/**', - glob.escapePath(path.resolve(config.root, config.build.outDir)) + '/**', - ...arraify(ignored), + ...arraifyIgnored, ], ignoreInitial: true, ignorePermissionErrors: true, From 0c545969f57391240c9bba950bb01ee4bdb802af Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 20 Feb 2024 17:06:14 +0800 Subject: [PATCH 2/3] chore: update --- packages/vite/src/node/watch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index ac20749737265e..2e96899fb4a858 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -13,7 +13,7 @@ export function resolveChokidarOptions( const arraifyIgnored = arraify(ignored) if (config.build.outDir) { arraifyIgnored.push( - glob.escapePath(path.resolve(config.root, config.build.outDir)), + glob.escapePath(path.resolve(config.root, config.build.outDir)) + '/**', ) } From ec5aa4321c72c7f34f04b6744020305333a8d24f Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 20 Feb 2024 17:34:00 +0800 Subject: [PATCH 3/3] refactor: update --- packages/vite/src/node/watch.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index 2e96899fb4a858..9c9972bdd3a471 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -9,22 +9,22 @@ export function resolveChokidarOptions( config: ResolvedConfig, options: WatchOptions | undefined, ): WatchOptions { - const { ignored = [], ...otherOptions } = options ?? {} - const arraifyIgnored = arraify(ignored) + 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) { - arraifyIgnored.push( + 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) + '/**', - ...arraifyIgnored, - ], + ignored, ignoreInitial: true, ignorePermissionErrors: true, ...otherOptions,