Skip to content

Commit

Permalink
fix(css): remove empty css chunks with cssCodeSplit: false
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
susnux committed May 3, 2024
1 parent 2bc5d3d commit 456e3cd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
}

if (chunkCSS) {
if (isPureCssChunk && (opts.format === 'es' || opts.format === 'cjs')) {
// this is a shared CSS-only chunk that is empty.
pureCssChunks.add(chunk)
}
if (config.build.cssCodeSplit) {
if (opts.format === 'es' || opts.format === 'cjs') {
if (isPureCssChunk) {
// this is a shared CSS-only chunk that is empty.
pureCssChunks.add(chunk)
}

const isEntry = chunk.isEntry && isPureCssChunk
const cssFullAssetName = ensureFileExt(chunk.name, '.css')
// if facadeModuleId doesn't exist or doesn't have a CSS extension,
Expand Down

0 comments on commit 456e3cd

Please sign in to comment.