From 4ec1315369c95c115c6271b6f93e1d9bf089c12f Mon Sep 17 00:00:00 2001 From: Gilles Piou Date: Fri, 23 Oct 2020 01:05:27 +0800 Subject: [PATCH] fix: avoid conflicting filename for sourcemaps (#375) Co-authored-by: Rahul Kadyan --- src/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7c67020..626565c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -127,7 +127,7 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { if (block) { return { code: block.content, - map: normalizeSourceMap(block.map), + map: normalizeSourceMap(block.map, id), } } } @@ -196,7 +196,7 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { return { code: result.code, - map: normalizeSourceMap(result.map!), + map: normalizeSourceMap(result.map!, id), } } else if (query.type === 'style') { debug(`transform(${id})`) @@ -263,7 +263,7 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { } else { return { code: result.code, - map: normalizeSourceMap(result.map!), + map: normalizeSourceMap(result.map!, id), } } } @@ -638,9 +638,14 @@ function _(any: any) { return JSON.stringify(any) } -function normalizeSourceMap(map: SFCTemplateCompileResults['map']): any { +function normalizeSourceMap(map: SFCTemplateCompileResults['map'], id: string): any { if (!map) return null as any + if (!id.includes('type=script')) { + map.file = id; + map.sources[0] = id; + } + return { ...map, version: Number(map.version),