Skip to content

Commit

Permalink
fix: dev sourcemap (#8269)
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho authored May 22, 2022
1 parent a4cc80b commit 505f75e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
7 changes: 2 additions & 5 deletions packages/vite/src/node/plugins/dynamicImportVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
const { include, exclude, warnOnError } =
config.build.dynamicImportVarsOptions
const filter = createFilter(include, exclude)
const isBuild = config.command === 'build'

return {
name: 'vite:dynamic-import-vars',

Expand Down Expand Up @@ -206,10 +206,7 @@ export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
}
return {
code: s.toString(),
map:
!isBuild || config.build.sourcemap
? s.generateMap({ hires: true })
: null
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function importGlobPlugin(config: ResolvedConfig): Plugin {
}
return {
code: result.s.toString(),
map: result.s.generateMap()
map: config.build.sourcemap ? result.s.generateMap() : null
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion playground/dynamic-import/__tests__/dynamic-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test('should load dynamic import with vars', async () => {
test('should load dynamic import with vars alias', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-alias'),
'hello',
'hi',
true
)
})
Expand Down
1 change: 1 addition & 0 deletions playground/dynamic-import/alias/hello.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function hello() {
return 'hello'
}
console.log('hello.js')
1 change: 1 addition & 0 deletions playground/dynamic-import/alias/hi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function hi() {
return 'hi'
}
console.log('hi.js')
13 changes: 8 additions & 5 deletions playground/dynamic-import/nested/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@ function text(el, text) {
document.querySelector(el).textContent = text
}

const base = 'hello'
let base = 'hello'

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

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

import(`../alias/${base}.js?raw`).then((mod) => {
text('.dynamic-import-with-vars-raw', JSON.stringify(mod))
})

base = 'hi'
import(`@/${base}.js`).then((mod) => {
text('.dynamic-import-with-vars-alias', mod.hi())
})

console.log('index.js')

0 comments on commit 505f75e

Please sign in to comment.