fix(nuxt): generate empty sourcemaps for wrappers (#20744)

This commit is contained in:
Daniel Roe 2023-05-09 16:57:23 +01:00 committed by GitHub
parent fd9b179f5a
commit eb8e9169d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,30 +53,37 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
const mode = query.nuxt_component
const bare = id.replace(/\?.*/, '')
if (mode === 'async') {
return [
return {
code: [
'import { defineAsyncComponent } from "vue"',
`export default defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => r.default))`
].join('\n')
].join('\n'),
map: null
}
} else if (mode === 'client') {
return [
return {
code: [
`import __component from ${JSON.stringify(bare)}`,
'import { createClientOnly } from "#app/components/client-only"',
'export default createClientOnly(__component)'
].join('\n')
].join('\n'),
map: null
}
} else if (mode === 'client,async') {
return [
return {
code: [
'import { defineAsyncComponent } from "vue"',
'import { createClientOnly } from "#app/components/client-only"',
`export default defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => createClientOnly(r.default)))`
].join('\n')
].join('\n'),
map: null
}
} else {
throw new Error(`Unknown component mode: ${mode}, this might be an internal bug of Nuxt.`)
}
}
if (!code.includes('#components')) {
return null
}
if (!code.includes('#components')) { return }
componentUnimport.modifyDynamicImports((imports) => {
imports.length = 0
@ -85,12 +92,11 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
})
const result = await componentUnimport.injectImports(code, id, { autoImport: false, transformVirtualImports: true })
if (!result) {
return null
}
if (!result) { return }
return {
code: result.code,
map: nuxt.options.sourcemap
map: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client
? result.s.generateMap({ hires: true })
: undefined
}