Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/bin/vite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/rolldown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'
}
},
Expand Down