diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d2b003927ff176..8a2211d05b4a59 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -120,6 +120,12 @@ Some errors are masked and hidden away because of the layers of abstraction and 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. +### Disabling Source Maps + +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. + +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. + ## Testing Vite against external packages 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`: diff --git a/packages/vite/bin/vite.js b/packages/vite/bin/vite.js index 487f7c89ce0e2c..23d11390d73dff 100755 --- a/packages/vite/bin/vite.js +++ b/packages/vite/bin/vite.js @@ -3,8 +3,10 @@ import { performance } from 'node:perf_hooks' import module from 'node:module' if (!import.meta.url.includes('node_modules')) { - // eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev - process.setSourceMapsEnabled(true) + if (!process.env.DEBUG_DISABLE_SOURCE_MAP) { + // eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev + process.setSourceMapsEnabled(true) + } process.on('unhandledRejection', (err) => { throw new Error('UNHANDLED PROMISE REJECTION', { cause: err }) diff --git a/packages/vite/rolldown.config.ts b/packages/vite/rolldown.config.ts index 03607a125accf7..d67c8bd8840537 100644 --- a/packages/vite/rolldown.config.ts +++ b/packages/vite/rolldown.config.ts @@ -11,6 +11,7 @@ const pkg = JSON.parse( readFileSync(new URL('./package.json', import.meta.url)).toString(), ) const __dirname = fileURLToPath(new URL('.', import.meta.url)) +const disableSourceMap = !!process.env.DEBUG_DISABLE_SOURCE_MAP const envConfig = defineConfig({ input: path.resolve(__dirname, 'src/client/env.ts'), @@ -186,7 +187,7 @@ function enableSourceMapsInWatchModePlugin(): Plugin { return { name: 'enable-source-maps', outputOptions(options) { - if (this.meta.watchMode) { + if (this.meta.watchMode && !disableSourceMap) { options.sourcemap = 'inline' } },