Skip to content

Commit 505f75e

Browse files
authored
fix: dev sourcemap (#8269)
1 parent a4cc80b commit 505f75e

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

packages/vite/src/node/plugins/dynamicImportVars.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
117117
const { include, exclude, warnOnError } =
118118
config.build.dynamicImportVarsOptions
119119
const filter = createFilter(include, exclude)
120-
const isBuild = config.command === 'build'
120+
121121
return {
122122
name: 'vite:dynamic-import-vars',
123123

@@ -206,10 +206,7 @@ export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
206206
}
207207
return {
208208
code: s.toString(),
209-
map:
210-
!isBuild || config.build.sourcemap
211-
? s.generateMap({ hires: true })
212-
: null
209+
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
213210
}
214211
}
215212
}

packages/vite/src/node/plugins/importMetaGlob.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function importGlobPlugin(config: ResolvedConfig): Plugin {
7575
}
7676
return {
7777
code: result.s.toString(),
78-
map: result.s.generateMap()
78+
map: config.build.sourcemap ? result.s.generateMap() : null
7979
}
8080
}
8181
}

playground/dynamic-import/__tests__/dynamic-import.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test('should load dynamic import with vars', async () => {
7171
test('should load dynamic import with vars alias', async () => {
7272
await untilUpdated(
7373
() => page.textContent('.dynamic-import-with-vars-alias'),
74-
'hello',
74+
'hi',
7575
true
7676
)
7777
})
+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export function hello() {
22
return 'hello'
33
}
4+
console.log('hello.js')

playground/dynamic-import/alias/hi.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export function hi() {
22
return 'hi'
33
}
4+
console.log('hi.js')

playground/dynamic-import/nested/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,19 @@ function text(el, text) {
7979
document.querySelector(el).textContent = text
8080
}
8181

82-
const base = 'hello'
82+
let base = 'hello'
8383

8484
import(`../alias/${base}.js`).then((mod) => {
8585
text('.dynamic-import-with-vars', mod.hello())
8686
})
8787

88-
import(`@/${base}.js`).then((mod) => {
89-
text('.dynamic-import-with-vars-alias', mod.hello())
90-
})
91-
9288
import(`../alias/${base}.js?raw`).then((mod) => {
9389
text('.dynamic-import-with-vars-raw', JSON.stringify(mod))
9490
})
91+
92+
base = 'hi'
93+
import(`@/${base}.js`).then((mod) => {
94+
text('.dynamic-import-with-vars-alias', mod.hi())
95+
})
96+
97+
console.log('index.js')

0 commit comments

Comments
 (0)