fix: inject __vite__mapDeps
code before sourcemap file comment
#15483
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
#14550 introduced
__vite__mapDeps
runtime function, which is appended to the chunk output duringgenerateBundle
hooks. Rollup's chunk already includes//# sourceMappingURL=
comment at this point, thusMagicString.append
would inject the code after such comment.This PR fixes this issue by using
MagicString.appendRight
to inject right before the sourcemap comment if found.Note that the issue manifested when
sourcemap: true
(i.e. separate sourcemap file) but not whensourcemap: "inline"
since the comment was re-appended in inline case:vite/packages/vite/src/node/plugins/importAnalysisBuild.ts
Lines 686 to 691 in 0cd4f82
While testing on browsers by previewing
playground/js-sourcemap
locally, I found that//# sourceMappingURL
comment appearing before__vite__mapDeps
seems to be actually fine (at least for Chrome). So, I'm a little worried that the cause of the original issue might be something different. I'll ask for the further detail in the issue.Here is what I tested (where both "before" and "after" look working however):
Screenshots
Additional context
A few related PRs I looked up while attempting this fix:
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).