From eea60838090ddae6b634c693b247a81826546e5b Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 4 Mar 2024 20:11:53 +0100 Subject: [PATCH] fix: update to check chunk.type --- .../vite/src/node/plugins/importAnalysisBuild.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 9406bec6bdc0ab..8779ef80f78e20 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -5,7 +5,7 @@ import type { ImportSpecifier, } from 'es-module-lexer' import { init, parse as parseImports } from 'es-module-lexer' -import type { OutputChunk, SourceMap } from 'rollup' +import type { SourceMap } from 'rollup' import type { RawSourceMap } from '@ampproject/remapping' import convertSourceMap from 'convert-source-map' import { @@ -377,16 +377,17 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { if (filename === ownerFilename) return if (analyzed.has(filename)) return analyzed.add(filename) - const chunk = bundle[filename] as OutputChunk | undefined + const chunk = bundle[filename] if (chunk) { deps.add(chunk.fileName) - if (chunk.imports) chunk.imports.forEach(addDeps) - // Ensure that the css imported by current chunk is loaded after the dependencies. - // So the style of current chunk won't be overwritten unexpectedly. - if (chunk.viteMetadata) + if (chunk.type === 'chunk') { + chunk.imports.forEach(addDeps) + // Ensure that the css imported by current chunk is loaded after the dependencies. + // So the style of current chunk won't be overwritten unexpectedly. chunk.viteMetadata!.importedCss.forEach((file) => { deps.add(file) }) + } } else { const removedPureCssFiles = removedPureCssFilesCache.get(config)!