Skip to content

Commit 3a30c0a

Browse files
authored
chore: add a way to disable source maps when developing Vite (#20168)
1 parent 89ca65b commit 3a30c0a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ Some errors are masked and hidden away because of the layers of abstraction and
120120

121121
You can set the `--debug` option to turn on debugging logs (e.g. `vite --debug resolve`). To see all debug logs, you can set `vite --debug *`, but be warned that it will be quite noisy. You can run `grep -r "createDebugger('vite:" packages/vite/src/` to see a list of available debug scopes.
122122

123+
### Disabling Source Maps
124+
125+
Source maps for Vite's source code are enabled by default when Vite is placed outside `node_modules` so that you can easily debug it. When bundling Vite in watch mode, source maps will be generated.
126+
127+
However, this behavior may not be desirable when you are developing source map related features. In that case, you can disable source maps by setting the `DEBUG_DISABLE_SOURCE_MAP` environment variable to `1` when running Vite (e.g. `DEBUG_DISABLE_SOURCE_MAP=1 vite`). This environment variable can also be used to disable source map generation.
128+
123129
## Testing Vite against external packages
124130

125131
You may wish to test your locally modified copy of Vite against another package that is built with Vite. For pnpm, after building Vite, you can use [`pnpm.overrides`](https://pnpm.io/package_json#pnpmoverrides) to do this. Note that `pnpm.overrides` must be specified in the root `package.json`, and you must list the package as a dependency in the root `package.json`:

packages/vite/bin/vite.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { performance } from 'node:perf_hooks'
33
import module from 'node:module'
44

55
if (!import.meta.url.includes('node_modules')) {
6-
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev
7-
process.setSourceMapsEnabled(true)
6+
if (!process.env.DEBUG_DISABLE_SOURCE_MAP) {
7+
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev
8+
process.setSourceMapsEnabled(true)
9+
}
810

911
process.on('unhandledRejection', (err) => {
1012
throw new Error('UNHANDLED PROMISE REJECTION', { cause: err })

packages/vite/rolldown.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const pkg = JSON.parse(
1111
readFileSync(new URL('./package.json', import.meta.url)).toString(),
1212
)
1313
const __dirname = fileURLToPath(new URL('.', import.meta.url))
14+
const disableSourceMap = !!process.env.DEBUG_DISABLE_SOURCE_MAP
1415

1516
const envConfig = defineConfig({
1617
input: path.resolve(__dirname, 'src/client/env.ts'),
@@ -186,7 +187,7 @@ function enableSourceMapsInWatchModePlugin(): Plugin {
186187
return {
187188
name: 'enable-source-maps',
188189
outputOptions(options) {
189-
if (this.meta.watchMode) {
190+
if (this.meta.watchMode && !disableSourceMap) {
190191
options.sourcemap = 'inline'
191192
}
192193
},

0 commit comments

Comments
 (0)