From eb8e9169d6e0538b8c9a2adecae6d9bea37408a4 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 9 May 2023 16:57:23 +0100 Subject: [PATCH] fix(nuxt): generate empty sourcemaps for wrappers (#20744) --- packages/nuxt/src/components/transform.ts | 48 +++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/nuxt/src/components/transform.ts b/packages/nuxt/src/components/transform.ts index 2a6c5dba6e..e4bda7dcbf 100644 --- a/packages/nuxt/src/components/transform.ts +++ b/packages/nuxt/src/components/transform.ts @@ -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 @@ -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 }