From ec3e9246a0cfe1b0fc67da3a162b03d2ef6675b2 Mon Sep 17 00:00:00 2001 From: underfin Date: Fri, 2 Aug 2024 15:55:18 +0800 Subject: [PATCH] fix: enable css and asset addWatchFile at dev --- packages/vite/src/node/plugins/asset.ts | 5 ++++- packages/vite/src/node/plugins/css.ts | 13 +++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 4642523eeb4b37..3aa6d35456ab96 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -175,7 +175,10 @@ export function assetPlugin(config: ResolvedConfig): Plugin { // raw requests, read from disk if (rawRE.test(id)) { const file = checkPublicFile(id, config) || cleanUrl(id) - // this.addWatchFile(file) + if (config.command !== 'build') { + // @ts-expect-error + this.addWatchFile(file) + } // raw query, read file and return as string return `export default ${JSON.stringify( await fsp.readFile(file, 'utf-8'), diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 5bdbe938df86d1..68e288252966f6 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -366,7 +366,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin { const { code: css, modules, - //deps, + deps, map, } = await compileCSS( id, @@ -379,11 +379,12 @@ export function cssPlugin(config: ResolvedConfig): Plugin { moduleCache.set(id, modules) } - // if (deps) { - // for (const file of deps) { - // this.addWatchFile(file) - // } - // } + if (deps && !isBuild) { + for (const file of deps) { + // @ts-expect-error + this.addWatchFile(file) + } + } return { code: css,