Skip to content

Commit f61d8b1

Browse files
bluwypatak-dev
authored andcommitted
perf(css): only replace empty chunk if imported (#16349)
1 parent a9bf430 commit f61d8b1

File tree

1 file changed

+5
-1
lines changed
  • packages/vite/src/node/plugins

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
868868
for (const file in bundle) {
869869
const chunk = bundle[file]
870870
if (chunk.type === 'chunk') {
871+
let chunkImportsPureCssChunk = false
871872
// remove pure css chunk from other chunk's imports,
872873
// and also register the emitted CSS files under the importer
873874
// chunks instead.
@@ -882,11 +883,14 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
882883
importedAssets.forEach((file) =>
883884
chunk.viteMetadata!.importedAssets.add(file),
884885
)
886+
chunkImportsPureCssChunk = true
885887
return false
886888
}
887889
return true
888890
})
889-
chunk.code = replaceEmptyChunk(chunk.code)
891+
if (chunkImportsPureCssChunk) {
892+
chunk.code = replaceEmptyChunk(chunk.code)
893+
}
890894
}
891895
}
892896

0 commit comments

Comments
 (0)