diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 14cd33ca..18bc6305 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -291,6 +291,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { options.value, this, ssr, + filename, + !!query.src, ) } else if (query.type === 'style') { return transformStyle( diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index d3a6350d..15e01b23 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -17,6 +17,8 @@ export async function transformTemplateAsModule( options: ResolvedOptions, pluginContext: TransformPluginContext, ssr: boolean, + filename: string, + isSrc: boolean, ): Promise<{ code: string map: any @@ -35,6 +37,15 @@ export async function transformTemplateAsModule( })` } + if (result.map && isSrc) { + const vueFileIndex = result.map.sources.findIndex( + (source) => source === descriptor.filename, + ) + if (vueFileIndex >= 0) { + result.map.sources[vueFileIndex] = filename + } + } + return { code: returnCode, map: result.map, diff --git a/playground/vue-sourcemap/Main.vue b/playground/vue-sourcemap/Main.vue index 8b092e88..d63d3799 100644 --- a/playground/vue-sourcemap/Main.vue +++ b/playground/vue-sourcemap/Main.vue @@ -7,6 +7,7 @@ +