diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 4c3ad50e83d77f..68eb075ee00e8c 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -953,8 +953,18 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return } + // vite:asset cleans up earlier assets of 'renderChunk', + // but with cssCodeSplit=false we may still emit CSS here. + // So is our responsibility to respect emitAssets + const canEmitAssets = + config.command !== 'build' || this.environment.config.build.emitAssets + // extract as single css bundle if no codesplit - if (!this.environment.config.build.cssCodeSplit && !hasEmitted) { + if ( + canEmitAssets && + !this.environment.config.build.cssCodeSplit && + !hasEmitted + ) { let extractedCss = '' const collected = new Set() // will be populated in order they are used by entry points