Skip to content

Commit bd52283

Browse files
fix: analysing build chunk without dependencies (#15469)
Co-authored-by: patak <[email protected]>
1 parent ab823ab commit bd52283

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/vite/src/node/plugins/importAnalysisBuild.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ImportSpecifier,
66
} from 'es-module-lexer'
77
import { init, parse as parseImports } from 'es-module-lexer'
8-
import type { OutputChunk, SourceMap } from 'rollup'
8+
import type { SourceMap } from 'rollup'
99
import type { RawSourceMap } from '@ampproject/remapping'
1010
import convertSourceMap from 'convert-source-map'
1111
import {
@@ -377,15 +377,17 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
377377
if (filename === ownerFilename) return
378378
if (analyzed.has(filename)) return
379379
analyzed.add(filename)
380-
const chunk = bundle[filename] as OutputChunk | undefined
380+
const chunk = bundle[filename]
381381
if (chunk) {
382382
deps.add(chunk.fileName)
383-
chunk.imports.forEach(addDeps)
384-
// Ensure that the css imported by current chunk is loaded after the dependencies.
385-
// So the style of current chunk won't be overwritten unexpectedly.
386-
chunk.viteMetadata!.importedCss.forEach((file) => {
387-
deps.add(file)
388-
})
383+
if (chunk.type === 'chunk') {
384+
chunk.imports.forEach(addDeps)
385+
// Ensure that the css imported by current chunk is loaded after the dependencies.
386+
// So the style of current chunk won't be overwritten unexpectedly.
387+
chunk.viteMetadata!.importedCss.forEach((file) => {
388+
deps.add(file)
389+
})
390+
}
389391
} else {
390392
const removedPureCssFiles =
391393
removedPureCssFilesCache.get(config)!

0 commit comments

Comments
 (0)