Skip to content

feat(build): chunk importmap#21580

Merged
sapphi-red merged 17 commits into
vitejs:mainfrom
sapphi-red:feat/chunk-importmap
Jun 15, 2026
Merged

feat(build): chunk importmap#21580
sapphi-red merged 17 commits into
vitejs:mainfrom
sapphi-red:feat/chunk-importmap

Conversation

@sapphi-red

@sapphi-red sapphi-red commented Feb 6, 2026

Copy link
Copy Markdown
Member

This PR implements build.chunkImportMap option, which utilizes import maps feature to optimize chunk caching efficiency.
This PR is based on #16552 and uses Rolldown's experimental importmaps feature. Huge thanks to @bhbs who have researched this topic and gave us the insights.

The implementation in the Vite core relies on import.meta.resolve. For that reason, only browsers with import.meta.resolve support are supported when this option is used.
To align with this, plugin-legacy now considers import.meta.resolve to be "widely-available". In other words, browsers without import.meta.resolve will use the legacy chunks instead of the modern chunks. (done in #21662) The plugin-legacy support for this feature is implemented by using the import map support in SystemJS.

Note that experimental.renderBuiltUrl currently does not work with this option. To properly support the combination of that option + this option, it requires more effort to design how to handle absolute URLs (e.g. how to support the case where renderBuiltUrl returns an absolute URL that should be mapped by the import map).

Also note that this optimization currently does not apply to CSS and assets. But this shouldn't affect largely as it will only invalidate the JS file that is importing them and would not affect the JS files that transitively imports the changed CSS / asset.

fixes #6773
fixes #10636
close #16552

@sapphi-red sapphi-red added p3-significant High priority enhancement (priority) trigger: preview labels Feb 10, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/plugin-legacy

pnpm add https://pkg.pr.new/@vitejs/plugin-legacy@21580 -D
npm i https://pkg.pr.new/@vitejs/plugin-legacy@21580 -D
yarn add https://pkg.pr.new/@vitejs/plugin-legacy@21580.tgz -D

vite

pnpm add https://pkg.pr.new/vite@21580 -D
npm i https://pkg.pr.new/vite@21580 -D
yarn add https://pkg.pr.new/vite@21580.tgz -D

commit: 4d79a03

@sapphi-red sapphi-red marked this pull request as ready for review February 13, 2026 06:53
@github-project-automation github-project-automation Bot moved this to Discussing in Team Board Feb 13, 2026
@sapphi-red sapphi-red changed the title feat: chunk importmap feat(build): chunk importmap Feb 13, 2026
@sapphi-red sapphi-red moved this from Discussing to Approved in Team Board Feb 18, 2026
@sapphi-red sapphi-red marked this pull request as draft February 19, 2026 04:02
@sapphi-red sapphi-red marked this pull request as ready for review February 19, 2026 07:23
@sapphi-red sapphi-red added this to the 8.1 milestone Mar 16, 2026
Comment thread packages/plugin-legacy/src/index.ts Outdated
@sapphi-red sapphi-red merged commit e180312 into vitejs:main Jun 15, 2026
19 of 20 checks passed
@sapphi-red sapphi-red deleted the feat/chunk-importmap branch June 15, 2026 02:16
@bhbs bhbs mentioned this pull request Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: build p3-significant High priority enhancement (priority) trigger: preview

Projects

Archived in project

1 participant