-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
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
and css.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 to false
to prevent the automatic injection of sourcemaps that happens here
vite/packages/vite/src/node/server/send.ts
Lines 59 to 63 in ba62be4
if (map && map.mappings) { | |
if (type === 'js' || type === 'css') { | |
content = getCodeWithSourcemap(type, content.toString(), map) | |
} | |
} |
Or, a bit more ambitiously, add a top level sourcemap
setting that, if set, would supercede build.sourcemap
, esbuild.sourcemap
, build.rollupOptions.output.sourcemap*
and css.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:
- Is a per-machine setting, so while one project might not benefit from sourcemaps, another project might still need them, requiring repeated toggling through context switches.
- Is a per-machine setting, so if it is known that the sourcemaps for a particular project are problematic, they cannot be turned off for all developers on that project.
Additional context
This would likely allow users to overcome (not a fix, but at least allow for a workaround) for the following issues:
- Debugging vite+vue+typescript using HMR is broken. Breakpoint on incorrect line numbers vite-plugin-vue#33
- Line numbers in TypeScript broken for Chrome/VSCode debugging #5834
- Add an option to entirely disable sourcemap generation underfin/vite-plugin-vue2#208
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.