Skip to content

fix(build): map CSS chunks in chunk import maps (fix #22946) - #22947

Merged
sapphi-red merged 4 commits into
vitejs:mainfrom
DebadityaHait:fix/chunk-importmap-css
Jul 17, 2026
Merged

sapphi-red merged 4 commits into
vitejs:mainfrom
DebadityaHait:fix/chunk-importmap-css

Conversation

@DebadityaHait

Copy link
Copy Markdown
Contributor

Fixes #22946

When build.chunkImportMap is enabled, dynamic JavaScript dependencies use stable import-map specifiers, but extracted CSS dependencies still use content-hashed filenames. A CSS-only change can therefore leave a parent chunk filename unchanged while changing its cached preload array.

This tracks each emitted CSS asset's originating chunk, adds a corresponding stable CSS entry to the generated import map, and lets preload rewriting use that stable specifier. Builds without chunkImportMap are unchanged.

I considered rewriting only the preload array or changing global asset filenames. The former would not give the browser a target mapping, while the latter would affect unrelated builds. Extending the generated import map keeps the change scoped to the experimental option.

Tests:

  • pnpm run build
  • pnpm run test-build chunk-importmap
  • pnpm exec eslint packages/vite/src/node/plugins/css.ts packages/vite/src/node/plugins/html.ts playground/chunk-importmap/__tests__/chunk-importmap.spec.ts

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: chunk import map labels Jul 17, 2026

@sapphi-red sapphi-red left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I added a new test case and some comments clarifying the behavior.

@sapphi-red
sapphi-red merged commit e16ff3a into vitejs:main Jul 17, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: chunk import map p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chunkImportMap css import uses contenthash

2 participants