-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Add a way to universally disable sourcemaps #9825
Comments
A single top-level sourcemap option to control all emitted source maps would be nice. Similar to Webpack's SourceMapDevToolPlugin which fulfills the same purpose there. I'm especially hoping for a option to exclude assets by path regexp from emitting a source map, so that for example third-party chunks can be excluded. |
I second this use case. I was surprised to find the proposed setting didn't already exist in some form. |
Basically you can't stop vite from changing your source JS files, in dev mode. And in production mode you have to constantly rebuild because |
I also need to disable it. Did anyone find a way to do this in the dev server ? |
You can achieve this by adding a plugin. import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
{
name: 'remove-sourcemaps',
transform(code) {
return {
code,
map: { mappings: '' }
}
}
}
]
}) |
Description
Since vite produces modern javascript, sourcemaps in development are often unnecessary as there is no significant transpilation that would make debugging difficult without them.
On the other hand, sourcemaps are notoriously difficult to get correct, and if they're ever wrong then it can ruin the whole debugging experience.
While they can be turned off for individual components of vite (e.g.
esbuild.sourcemap
andcss.devSourcemap
), the dev server will still unconditionally inject sourcemaps from any plugin that produces them (like vite-plugin-vue2).Suggested solution
Add a setting
server.sourcemap
that can be set tofalse
to prevent the automatic injection of sourcemaps that happens herevite/packages/vite/src/node/server/send.ts
Lines 59 to 63 in ba62be4
Or, a bit more ambitiously, add a top level
sourcemap
setting that, if set, would supercedebuild.sourcemap
,esbuild.sourcemap
,build.rollupOptions.output.sourcemap*
andcss.devSourcemap
. I realize that individual plugins could still inject their own inline sourcemaps into their emitted code, but having a single central setting for this would also encourage plugin authors to respect this setting.Alternative
Disabling sourcemaps in the browser dev tools can achieve this end, but this has a few problems:
Additional context
This would likely allow users to overcome (not a fix, but at least allow for a workaround) for the following issues:
Validations
The text was updated successfully, but these errors were encountered: