Skip to content

Commit 15a6ebb

Browse files
authored
fix(css): only use files the current bundle contains (#16684)
1 parent f0fb987 commit 15a6ebb

File tree

1 file changed

+7
-3
lines changed
  • packages/vite/src/node/plugins

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,13 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
884884
.map((chunk) => [chunk.preliminaryFileName, chunk.fileName]),
885885
)
886886

887-
const pureCssChunkNames = [...pureCssChunks].map(
888-
(pureCssChunk) => prelimaryNameToChunkMap[pureCssChunk.fileName],
889-
)
887+
// When running in watch mode the generateBundle is called once per output format
888+
// in this case the `bundle` is not populated with the other output files
889+
// but they are still in `pureCssChunks`.
890+
// So we need to filter the names and only use those who are defined
891+
const pureCssChunkNames = [...pureCssChunks]
892+
.map((pureCssChunk) => prelimaryNameToChunkMap[pureCssChunk.fileName])
893+
.filter(Boolean)
890894

891895
const replaceEmptyChunk = getEmptyChunkReplacer(
892896
pureCssChunkNames,

0 commit comments

Comments
 (0)