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

Limited Source map generation #19187

Open
4 tasks done
pjebs opened this issue Jan 12, 2025 · 2 comments
Open
4 tasks done

Limited Source map generation #19187

pjebs opened this issue Jan 12, 2025 · 2 comments

Comments

@pjebs
Copy link

pjebs commented Jan 12, 2025

Description

This is related to #19186 (as an alternative solution to that proposal).
Source Maps are too large for analysis in production during production. (I know it's not the normal way)

Vite should have an option to generate a very limited source map.
The ability for it to record ONLY the original filename of files in a limited set of directories. (No line numbers, character positions etc).

The intention is to analyse stack traces.

Suggested solution

Limited Source maps

Alternative

No response

Additional context

No response

Validations

@pjebs
Copy link
Author

pjebs commented Jan 12, 2025

I'm not talkign about ignoreList etc: https://developer.chrome.com/docs/devtools/x-google-ignore-list to hide it during debugging in the browser.

I'm talking about reducing the filesize of the sourcemap file itself by REMOVING that information.

One solution from source map:

  1. Remove sourceContent key
  2. Remove sources for irrelevant files
  3. Remove line number and position mapping data (if not possible, make it all line 0, character 0 for each source file)

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 13, 2025

There was a related discussion about avoid generating source maps for node_modules #17923 (comment).

I think this is somewhat possible from a plugin by manipulating mappings for selected files. Here is an example to force empty mappings for some files https://stackblitz.com/edit/vitejs-vite-xxt3g3ph?file=vite.config.ts (it should be tested locally as stackblitz's browser source map seems not working).

export default defineConfig({
  build: {
    sourcemap: true,
  },
  plugins: [
    {
      name: 'remove-source-map',
      enforce: 'post',
      transform(code, id, options) {
        if (id.endsWith('b.js')) {
          return { code, map: { mappings: '' } };
        }
      },
    },
  ],
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants