Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export async function transformTemplateAsModule(
options: ResolvedOptions,
pluginContext: TransformPluginContext,
ssr: boolean,
filename: string,
isSrc: boolean,
): Promise<{
code: string
map: any
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions playground/vue-sourcemap/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<SassWithImport />
<Less />
<SrcImport />
<SrcImportHtml />
<NoScript />
<NoTemplate />
</template>
Expand All @@ -19,6 +20,7 @@ import Sass from './Sass.vue'
import SassWithImport from './SassWithImport.vue'
import Less from './Less.vue'
import SrcImport from './src-import/SrcImport.vue'
import SrcImportHtml from './src-import-html/SrcImportHtml.vue'
import NoScript from './NoScript.vue'
import NoTemplate from './NoTemplate.vue'
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ exports[`serve:vue-sourcemap > src imported > serve-src-imported 1`] = `
}
`;

exports[`serve:vue-sourcemap > src imported html > serve-html 1`] = `
{
"mappings": ";;;wBAAA,oBAA8B,WAA3B,mBAAuB",
"sources": [
"src-import.html",
],
Comment on lines +321 to +323
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this fix, this sources was ['SrcImportHtml.vue']. So the vue file's content was replaced with the html file's content (= the content in sourcesContent)

"sourcesContent": [
"<p>&lt;src-import-html&gt;</p>
",
],
"version": 3,
}
`;

exports[`serve:vue-sourcemap > src imported sass > serve-src-imported-sass 1`] = `
{
"mappings": "AAAA;EACE;;ACCF;EACE",
Expand Down
12 changes: 12 additions & 0 deletions playground/vue-sourcemap/__tests__/vue-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions playground/vue-sourcemap/src-import-html/SrcImportHtml.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template src="./src-import.html" />

<script setup lang="ts">
console.log('src-import-html')
</script>
1 change: 1 addition & 0 deletions playground/vue-sourcemap/src-import-html/src-import.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>&lt;src-import-html&gt;</p>