Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cacheDir should be ignored from watch #10242

Merged
merged 4 commits into from Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vite/src/node/build.ts
Expand Up @@ -574,6 +574,7 @@ async function doBuild(
}

const resolvedChokidarOptions = resolveChokidarOptions(
config,
config.build.watch.chokidar
)

Expand Down
12 changes: 7 additions & 5 deletions packages/vite/src/node/config.ts
Expand Up @@ -530,11 +530,13 @@ export async function resolveConfig(

// resolve cache directory
const pkgPath = lookupFile(resolvedRoot, [`package.json`], { pathOnly: true })
const cacheDir = config.cacheDir
? path.resolve(resolvedRoot, config.cacheDir)
: pkgPath
? path.join(path.dirname(pkgPath), `node_modules/.vite`)
: path.join(resolvedRoot, `.vite`)
const cacheDir = normalizePath(
config.cacheDir
? path.resolve(resolvedRoot, config.cacheDir)
: pkgPath
? path.join(path.dirname(pkgPath), `node_modules/.vite`)
: path.join(resolvedRoot, `.vite`)
)

const assetsFilter = config.assetsInclude
? createFilter(config.assetsInclude)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Expand Up @@ -304,7 +304,7 @@ export async function createServer(
const httpsOptions = await resolveHttpsConfig(config.server.https)
const { middlewareMode } = serverConfig

const resolvedWatchOptions = resolveChokidarOptions({
const resolvedWatchOptions = resolveChokidarOptions(config, {
disableGlobbing: true,
...serverConfig.watch
})
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/watch.ts
@@ -1,6 +1,9 @@
import { escapePath } from 'fast-glob'
import type { WatchOptions } from 'dep-types/chokidar'
import type { ResolvedConfig } from '.'

export function resolveChokidarOptions(
config: ResolvedConfig,
options: WatchOptions | undefined
): WatchOptions {
const { ignored = [], ...otherOptions } = options ?? {}
Expand All @@ -10,6 +13,7 @@ export function resolveChokidarOptions(
'**/.git/**',
'**/node_modules/**',
'**/test-results/**', // Playwright
escapePath(config.cacheDir) + '/**',
...(Array.isArray(ignored) ? ignored : [ignored])
],
ignoreInitial: true,
Expand Down