fix(build): preserve preload deps in chunkImportMap when base is not / (fix #23350) - #23361
Open
santusht06 wants to merge 2 commits into
Open
fix(build): preserve preload deps in chunkImportMap when base is not / (fix #23350)#23361santusht06 wants to merge 2 commits into
santusht06 wants to merge 2 commits into
Conversation
official-burak
left a comment
There was a problem hiding this comment.
The fallback is the right idea. resolveRolldownOptions injects baseUrl: base only into the object it passes to Rolldown, so environment.config.build.rolldownOptions.experimental.chunkImportMap never gets it unless the user set it themselves. Reading chunkImportMap.baseUrl from that config will keep missing, which is why the strip falls back to '/' and the preload map drops.
ResolvedEnvironmentOptions already has base?: string, so this does not need as any:
return options.base ?? '/'A second fixture with base: './' would be useful. That is the other value Vite uses, and k.slice(baseUrl.length) depends on the exact prefix Rolldown wrote.
Author
|
Thanks for the review @official-burak! Updated in latest commit:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #23350.
When
build.chunkImportMapis enabled andbaseis configured to a non-root path (e.g.base: '/sub/'):baseUrl: base(e.g./sub/assets/...).getImportMapBaseUrl(), it checkedoptions.build.rolldownOptions.experimental?.chunkImportMap?.baseUrland defaulted to'/'.'sub/assets/...', which mismatched bundle keys ('assets/...').importAnalysisBuild.tsmissed, dropping the__vite__mapDepsdependency list from lazy chunks and leaving lazy CSS un-preloaded.Solution
getImportMapBaseUrlinpackages/vite/src/node/plugins/html.tsto return(options as any).base ?? '/'whenchunkImportMap.baseUrlis not explicitly overridden onrolldownOptions.packages/vite/src/node/__tests__/build.spec.tsensuring preload dependency mappings are preserved with non-root base.Validation
pnpm run buildpnpm vitest run packages/vite/src/node/__tests__/build.spec.ts(68/68 passed)pnpm run typecheck(0 errors)pnpm run lint(0 errors)