Skip to content

Commit 0b65d21

Browse files
committed
fix(plugin-vue): handle sourcemap with empty script code
1 parent 2e1287f commit 0b65d21

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/plugin-vue/src/main.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,19 @@ export async function transformMain(
196196

197197
let resolvedMap: RawSourceMap | undefined = undefined
198198
if (options.sourceMap) {
199-
if (scriptMap && templateMap) {
199+
if (templateMap) {
200200
// if the template is inlined into the main module (indicated by the presence
201201
// of templateMap), we need to concatenate the two source maps.
202-
202+
const from = scriptMap ?? {
203+
version: 3,
204+
sources: [],
205+
names: [],
206+
mappings: '',
207+
}
203208
const gen = fromMap(
204209
// version property of result.map is declared as string
205210
// but actually it is `3`
206-
scriptMap as Omit<RawSourceMap, 'version'> as TraceEncodedSourceMap,
211+
from as Omit<RawSourceMap, 'version'> as TraceEncodedSourceMap,
207212
)
208213
const tracer = new TraceMap(
209214
// same above
@@ -231,8 +236,7 @@ export async function transformMain(
231236
// of the main module compile result, which has outdated sourcesContent.
232237
resolvedMap.sourcesContent = templateMap.sourcesContent
233238
} else {
234-
// if one of `scriptMap` and `templateMap` is empty, use the other one
235-
resolvedMap = scriptMap ?? templateMap
239+
resolvedMap = scriptMap
236240
}
237241
}
238242

0 commit comments

Comments
 (0)