From d76d4837d28e58fda880e8f10c106ce4cb48e75f Mon Sep 17 00:00:00 2001 From: underfin Date: Thu, 8 Aug 2024 19:08:33 +0800 Subject: [PATCH] revert: remove css chunk --- packages/vite/src/node/plugins/css.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 19cdecc650827e..17c89be8a4fc0c 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -776,7 +776,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { generatedAssets .get(config)! .set(referenceId, { originalName: originalFilename, isEntry }) - getChunkMetadata(chunk.name)!.importedCss.add(this.getFileName(referenceId)) + getChunkMetadata(chunk.name)!.importedCss.add( + this.getFileName(referenceId), + ) } else if (!config.build.ssr) { // legacy build and inline css @@ -929,7 +931,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // chunks instead. chunk.imports = chunk.imports.filter((file) => { if (pureCssChunkNames.includes(file)) { - const { importedCss, importedAssets } = getChunkMetadata((bundle[file] as OutputChunk).name)! + const { importedCss, importedAssets } = getChunkMetadata( + (bundle[file] as OutputChunk).name, + )! importedCss.forEach((file) => getChunkMetadata(chunk.name)!.importedCss.add(file), ) @@ -947,14 +951,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } } - // TODO The css module will be treated as a common-js like module, remove it from the bundle - - // const removedPureCssFiles = removedPureCssFilesCache.get(config)! - // pureCssChunkNames.forEach((fileName) => { - // removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk) - // delete bundle[fileName] - // delete bundle[`${fileName}.map`] - // }) + const removedPureCssFiles = removedPureCssFilesCache.get(config)! + pureCssChunkNames.forEach((fileName) => { + removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk) + delete bundle[fileName] + delete bundle[`${fileName}.map`] + }) } }, } @@ -2833,7 +2835,8 @@ function formatStylusSourceMap( if (!mapBefore) return undefined const map = { ...mapBefore } - const resolveFromRoot = (p: string | null) => normalizePath(path.resolve(root, p!)) + const resolveFromRoot = (p: string | null) => + normalizePath(path.resolve(root, p!)) if (map.file) { map.file = resolveFromRoot(map.file)