Skip to content

Commit 456e3cd

Browse files
committed
fix(css): remove empty css chunks with cssCodeSplit: false
Resolves #16582 When setting `cssCodeSplit: false` the styles are still split into one style file. But currently the imported CSS results in empty chunks, as in the current implementation empty chunks are only removed when `cssCodeSplit` was set to `true`. So this also adds empty style chunks to `pureCSSChunks` even with `cssCodeSplit: false`. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 2bc5d3d commit 456e3cd

File tree

1 file changed

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

1 file changed

+4
-5
lines changed

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
723723
}
724724

725725
if (chunkCSS) {
726+
if (isPureCssChunk && (opts.format === 'es' || opts.format === 'cjs')) {
727+
// this is a shared CSS-only chunk that is empty.
728+
pureCssChunks.add(chunk)
729+
}
726730
if (config.build.cssCodeSplit) {
727731
if (opts.format === 'es' || opts.format === 'cjs') {
728-
if (isPureCssChunk) {
729-
// this is a shared CSS-only chunk that is empty.
730-
pureCssChunks.add(chunk)
731-
}
732-
733732
const isEntry = chunk.isEntry && isPureCssChunk
734733
const cssFullAssetName = ensureFileExt(chunk.name, '.css')
735734
// if facadeModuleId doesn't exist or doesn't have a CSS extension,

0 commit comments

Comments
 (0)