Skip to content

Commit 75dbca2

Browse files
shigmasapphi-red
andauthoredDec 3, 2022
fix: cacheDir should be ignored from watch (#10242)
Co-authored-by: sapphi-red <green@sapphi.red>
1 parent 5935619 commit 75dbca2

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed
 

‎packages/vite/src/node/build.ts

+1
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ async function doBuild(
620620
config.logger.info(colors.cyan(`\nwatching for file changes...`))
621621

622622
const resolvedChokidarOptions = resolveChokidarOptions(
623+
config,
623624
config.build.watch.chokidar
624625
)
625626

‎packages/vite/src/node/config.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,13 @@ export async function resolveConfig(
530530

531531
// resolve cache directory
532532
const pkgPath = lookupFile(resolvedRoot, [`package.json`], { pathOnly: true })
533-
const cacheDir = config.cacheDir
534-
? path.resolve(resolvedRoot, config.cacheDir)
535-
: pkgPath
536-
? path.join(path.dirname(pkgPath), `node_modules/.vite`)
537-
: path.join(resolvedRoot, `.vite`)
533+
const cacheDir = normalizePath(
534+
config.cacheDir
535+
? path.resolve(resolvedRoot, config.cacheDir)
536+
: pkgPath
537+
? path.join(path.dirname(pkgPath), `node_modules/.vite`)
538+
: path.join(resolvedRoot, `.vite`)
539+
)
538540

539541
const assetsFilter =
540542
config.assetsInclude &&

‎packages/vite/src/node/server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export async function createServer(
315315
const httpsOptions = await resolveHttpsConfig(config.server.https)
316316
const { middlewareMode } = serverConfig
317317

318-
const resolvedWatchOptions = resolveChokidarOptions({
318+
const resolvedWatchOptions = resolveChokidarOptions(config, {
319319
disableGlobbing: true,
320320
...serverConfig.watch
321321
})

‎packages/vite/src/node/watch.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { escapePath } from 'fast-glob'
12
import type { WatchOptions } from 'dep-types/chokidar'
3+
import type { ResolvedConfig } from '.'
24

35
export function resolveChokidarOptions(
6+
config: ResolvedConfig,
47
options: WatchOptions | undefined
58
): WatchOptions {
69
const { ignored = [], ...otherOptions } = options ?? {}
@@ -10,6 +13,7 @@ export function resolveChokidarOptions(
1013
'**/.git/**',
1114
'**/node_modules/**',
1215
'**/test-results/**', // Playwright
16+
escapePath(config.cacheDir) + '/**',
1317
...(Array.isArray(ignored) ? ignored : [ignored])
1418
],
1519
ignoreInitial: true,

0 commit comments

Comments
 (0)
Please sign in to comment.