Skip to content

Commit 279ab0d

Browse files
authored
chore: fix source map support when developing Vite (#20167)
1 parent 0d60667 commit 279ab0d

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

packages/vite/bin/vite.js

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

55
if (!import.meta.url.includes('node_modules')) {
6-
try {
7-
// only available as dev dependency
8-
await import('source-map-support').then((r) => r.default.install())
9-
} catch {}
6+
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev
7+
process.setSourceMapsEnabled(true)
108

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

packages/vite/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
"sass": "^1.89.0",
145145
"sass-embedded": "^1.89.0",
146146
"sirv": "^3.0.1",
147-
"source-map-support": "^0.5.21",
148147
"strip-literal": "^3.0.0",
149148
"terser": "^5.39.2",
150149
"tsconfck": "^3.1.6",

packages/vite/rolldown.config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import licensePlugin from './rollupLicensePlugin'
1010
const pkg = JSON.parse(
1111
readFileSync(new URL('./package.json', import.meta.url)).toString(),
1212
)
13-
1413
const __dirname = fileURLToPath(new URL('.', import.meta.url))
1514

1615
const envConfig = defineConfig({
@@ -147,6 +146,7 @@ const nodeConfig = defineConfig({
147146
'Vite',
148147
) as Plugin,
149148
writeTypesPlugin(),
149+
enableSourceMapsInWatchModePlugin(),
150150
externalizeDepsInWatchPlugin(),
151151
],
152152
})
@@ -162,7 +162,7 @@ const moduleRunnerConfig = defineConfig({
162162
'rollup/parseAst',
163163
...Object.keys(pkg.dependencies),
164164
],
165-
plugins: [bundleSizeLimit(54)],
165+
plugins: [bundleSizeLimit(54), enableSourceMapsInWatchModePlugin()],
166166
output: {
167167
...sharedNodeOptions.output,
168168
minify: {
@@ -182,6 +182,17 @@ export default defineConfig([
182182

183183
// #region Plugins
184184

185+
function enableSourceMapsInWatchModePlugin(): Plugin {
186+
return {
187+
name: 'enable-source-maps',
188+
outputOptions(options) {
189+
if (this.meta.watchMode) {
190+
options.sourcemap = 'inline'
191+
}
192+
},
193+
}
194+
}
195+
185196
function writeTypesPlugin(): Plugin {
186197
return {
187198
name: 'write-types',

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)