Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dev sourcemap #8269

Merged
merged 2 commits into from May 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/vite/src/node/plugins/dynamicImportVars.ts
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
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
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
@@ -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
@@ -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
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')