-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for injecting debug IDs #18763
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR @timfish! Sounds good to me. Would it be possible to move the new test to the |
Yep, I'll do that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll add this one to the vite 6.1 milestone, and let others take a look too. We plan to start merging PRs for the 6.1 beta next week.
Oops. Looks like I need to update the snapshots! |
Debug IDs are detailed in the TC39 proposal.
Debug IDs are unique IDs generated from a deterministic hash of the source code which are then injected/included in both source and sourcemap. They can be used to easily identify the correct sourcemaps in production.
I've recently added support for injecting debug IDs to webpack, Rollup, and Rolldown and wanted to get them working in Vite too.
Since we're only concerned with production builds, I'd assumed it would work simply by passing the new Rollup output option:
Unfortunately this didn't work out-of-the-box with all output assets because in some cases, after Rollup output,
buildImportAnalysisPlugin
modifies the source code, updates the sourcemap and then outputs the new sourcemap with no debug ID.In an Ideal World™ we would re-hash the source to get an updated ID and replace the debug ID injected by Rollup in the source and sourcemap. I don't know the Vite code that well but it looks like this would add a lot of code to Vite and is likely excessive.
It looks like
buildImportAnalysisPlugin
is adding to the source code in a deterministic way so I have determined that it's likely safe to just retain the ID computed previously in Rollup and copy it to the new sourcemap.To finish this PR:
debugId
toSourceMap
types rollup/rollup#5751