fix: source map for webpack nuxt-setup-loader (#236)

This commit is contained in:
Anthony Fu 2021-06-17 17:56:21 +08:00 committed by GitHub
parent f32af4bdb6
commit 58327824fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 6 deletions

View File

@ -4,7 +4,7 @@ export default defineBuildConfig({
declaration: false, declaration: false,
entries: [ entries: [
'src/index', 'src/index',
'src/loaders/nuxt-setup' 'src/loaders/nuxt-setup-loader'
], ],
dependencies: [ dependencies: [
'@nuxt/kit', '@nuxt/kit',

View File

@ -1,10 +1,9 @@
const DEFINE_COMPONENT_VUE = '_defineComponent(' const DEFINE_COMPONENT_VUE = '_defineComponent('
const DEFINE_COMPONENT_NUXT = '_defineNuxtComponent(' const DEFINE_COMPONENT_NUXT = '_defineNuxtComponent('
export default function NuxtSetupLoader (code: string) { export default function NuxtSetupLoader (code: string, map: any) {
if (code && code.includes(DEFINE_COMPONENT_VUE)) { if (code && code.includes(DEFINE_COMPONENT_VUE)) {
// TODO: Add sourcemap hints code = 'import { defineNuxtComponent as _defineNuxtComponent } from "@nuxt/app";' + code.replace(DEFINE_COMPONENT_VUE, DEFINE_COMPONENT_NUXT)
code = 'import { defineNuxtComponent as _defineNuxtComponent } from "@nuxt/app"\n' + code.replace(DEFINE_COMPONENT_VUE, DEFINE_COMPONENT_NUXT)
} }
return code this.callback(null, code, map)
} }

View File

@ -10,7 +10,7 @@ export default class NuxtSetupTransformerPlugin {
enforce: 'post', enforce: 'post',
use: [{ use: [{
ident: 'NuxtSetupTransformerPlugin', ident: 'NuxtSetupTransformerPlugin',
loader: require.resolve('@nuxt/webpack-builder/dist/nuxt-setup') loader: require.resolve('@nuxt/webpack-builder/dist/nuxt-setup-loader')
}] }]
}) })
} }