Skip to content

Commit

Permalink
fix(nuxt): generate empty sourcemaps for wrappers (nuxt#20744)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 9, 2023
1 parent fd9b179 commit eb8e916
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions packages/nuxt/src/components/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,37 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
const mode = query.nuxt_component
const bare = id.replace(/\?.*/, '')
if (mode === 'async') {
return [
'import { defineAsyncComponent } from "vue"',
`export default defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => r.default))`
].join('\n')
return {
code: [
'import { defineAsyncComponent } from "vue"',
`export default defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => r.default))`
].join('\n'),
map: null
}
} else if (mode === 'client') {
return [
`import __component from ${JSON.stringify(bare)}`,
'import { createClientOnly } from "#app/components/client-only"',
'export default createClientOnly(__component)'
].join('\n')
return {
code: [
`import __component from ${JSON.stringify(bare)}`,
'import { createClientOnly } from "#app/components/client-only"',
'export default createClientOnly(__component)'
].join('\n'),
map: null
}
} else if (mode === 'client,async') {
return [
'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')
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'),
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
Expand All @@ -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
}
Expand Down

0 comments on commit eb8e916

Please sign in to comment.