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 @@
<src-import-html>
+", + ], + "version": 3, +} +`; + exports[`serve:vue-sourcemap > src imported sass > serve-src-imported-sass 1`] = ` { "mappings": "AAAA;EACE;;ACCF;EACE", diff --git a/playground/vue-sourcemap/__tests__/vue-sourcemap.spec.ts b/playground/vue-sourcemap/__tests__/vue-sourcemap.spec.ts index 45a1d776..7af759e0 100644 --- a/playground/vue-sourcemap/__tests__/vue-sourcemap.spec.ts +++ b/playground/vue-sourcemap/__tests__/vue-sourcemap.spec.ts @@ -91,6 +91,18 @@ describe.runIf(isServe)('serve:vue-sourcemap', () => { ) }) + test('src imported html', async () => { + const res = await page.request.get( + new URL( + './src-import-html/src-import.html?import&vue&type=template&src=true&lang.js', + page.url(), + ).href, + ) + const js = await res.text() + const map = extractSourcemap(js) + expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-html') + }) + test('no script', async () => { const res = await page.request.get( new URL('./NoScript.vue', page.url()).href, diff --git a/playground/vue-sourcemap/src-import-html/SrcImportHtml.vue b/playground/vue-sourcemap/src-import-html/SrcImportHtml.vue new file mode 100644 index 00000000..79e3f7b0 --- /dev/null +++ b/playground/vue-sourcemap/src-import-html/SrcImportHtml.vue @@ -0,0 +1,5 @@ + + + diff --git a/playground/vue-sourcemap/src-import-html/src-import.html b/playground/vue-sourcemap/src-import-html/src-import.html new file mode 100644 index 00000000..7202ea93 --- /dev/null +++ b/playground/vue-sourcemap/src-import-html/src-import.html @@ -0,0 +1 @@ +<src-import-html>