fix: update to check chunk.type

This commit is contained in:
patak 2024-03-04 20:05:55 +01:00
parent 4d569dca48
commit cf39ab3406

View File

@ -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)!