Skip to content
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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

timfish
Copy link

@timfish timfish commented Nov 26, 2024

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:

import { defineConfig } from 'vite';

export default defineConfig({
  root: './src',
  mode: 'production',
  build: {
    outDir: './dist',
    sourcemap: true,
    rollupOptions: {
      output: {
        sourcemapDebugIds: true,
      }
    }
  }
});

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:

@timfish timfish changed the title feat: Add support for injecting debug IDs feat: add support for injecting debug IDs Nov 26, 2024
@timfish timfish marked this pull request as draft December 4, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant