fix: __VITE_PRELOAD__ replacement error, fix #3051 #4163
Merged
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
fix #3051
When there is only one dynamic import, the input parameter
deps
of thepreload
function,vite/packages/vite/src/node/plugins/importAnalysisBuild.ts
Lines 23 to 28 in 98d95e3
when
terser
compresses for the third time, it will think thatdeps
is a constant string, move directly to the place of call and delete the input parameters.Before
terser minify
,complete file,before.txt:After
terser minify
,complete file,after.txt:The above behavior will cause the
__VITE_PRELOAD__
marker to move from the back of theimport
statement to the front, causing thecode.indexOf(preloadMarker, end)
to not find the mark,resulting in no replacement of the__VITE_PRELOAD__
vite/packages/vite/src/node/plugins/importAnalysisBuild.ts
Lines 265 to 275 in 98d95e3
Finally,
__VITE_PRELOAD__
was incorrectly replaced withvoid 0
by the following codevite/packages/vite/src/node/plugins/importAnalysisBuild.ts
Lines 282 to 284 in 98d95e3
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).