Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css): only use files the current bundle contains #16684

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,13 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
.map((chunk) => [chunk.preliminaryFileName, chunk.fileName]),
)

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

const replaceEmptyChunk = getEmptyChunkReplacer(
pureCssChunkNames,
Expand Down
Loading