Skip to content

Commit

Permalink
perf(css): only replace empty chunk if imported (#16349)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Apr 5, 2024
1 parent c0ec6be commit e2658ad
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/vite/src/node/plugins/css.ts
Expand Up @@ -860,6 +860,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
for (const file in bundle) {
const chunk = bundle[file]
if (chunk.type === 'chunk') {
let chunkImportsPureCssChunk = false
// remove pure css chunk from other chunk's imports,
// and also register the emitted CSS files under the importer
// chunks instead.
Expand All @@ -874,11 +875,14 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
importedAssets.forEach((file) =>
chunk.viteMetadata!.importedAssets.add(file),
)
chunkImportsPureCssChunk = true
return false
}
return true
})
chunk.code = replaceEmptyChunk(chunk.code)
if (chunkImportsPureCssChunk) {
chunk.code = replaceEmptyChunk(chunk.code)
}
}
}

Expand Down

0 comments on commit e2658ad

Please sign in to comment.