feat: add support for injecting debug IDs #18763
Open
+250
−24
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.
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 might be overkill.
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.I'll cc @lforst here since he wrote the proposal and will be able to confirm whether this compromise is ok.
To finish this PR:
magic-string
need to be merged, released and then released in Rollup feat: IncludedebugId
inSourceMap
types Rich-Harris/magic-string#294