fix: inject __vite__mapDeps code before sourcemap file comment - #15483
Conversation
|
|
bluwy
left a comment
There was a problem hiding this comment.
Looks great! Thanks for the fix.
While testing on browsers by previewing
playground/js-sourcemaplocally, I found that//# sourceMappingURLcomment appearing before__vite__mapDepsseems 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.
I've seen other toolings before that mandated sourcemap comments to always come last, so I think it make sense to fix this still.
|
The spec says the comment should be at the end, so I think it's a valid fix, too.
|
|
@hi-ogawa works great, thanks! |
Description
#14550 introduced
__vite__mapDepsruntime function, which is appended to the chunk output duringgenerateBundlehooks. Rollup's chunk already includes//# sourceMappingURL=comment at this point, thusMagicString.appendwould inject the code after such comment.This PR fixes this issue by using
MagicString.appendRightto 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-sourcemaplocally, I found that//# sourceMappingURLcomment appearing before__vite__mapDepsseems 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).