@@ -5,6 +5,7 @@ import loaderUtils from 'loader-utils'
55import { VueLoaderOptions } from './'
66import { SourceMapConsumer , RawSourceMap } from 'source-map'
77import { compileTemplate , generateCodeFrame } from '@vue/compiler-sfc'
8+ import mergeSourceMap from 'merge-source-map'
89
910// Loader that compiles raw template into JavaScript functions.
1011// This is injected by the global pitcher (../pitch) for template
@@ -21,12 +22,13 @@ const TemplateLoader: webpack.loader.Loader = function(source, inMap) {
2122
2223 // const isServer = loaderContext.target === 'node'
2324 // const isProduction = options.productionMode || loaderContext.minimize || process.env.NODE_ENV === 'production'
24- const query = qs . parse ( this . resourceQuery . slice ( 1 ) )
25+ const query = qs . parse ( loaderContext . resourceQuery . slice ( 1 ) )
2526 const scopeId = query . scoped ? `data-v-${ query . id } ` : null
2627
2728 const compiled = compileTemplate ( {
2829 source,
29- filename : this . resourcePath ,
30+ // avoid source content overwriting the original
31+ filename : loaderContext . resourcePath ,
3032 compiler : options . compiler ,
3133 compilerOptions : {
3234 ...options . compilerOptions ,
@@ -69,7 +71,12 @@ const TemplateLoader: webpack.loader.Loader = function(source, inMap) {
6971 } )
7072 }
7173
72- const { code, map } = compiled
74+ let { code, map } = compiled
75+ if ( map && inMap ) {
76+ // avoid overwritting original *.vue source during merge
77+ map . sourcesContent = [ ]
78+ map = mergeSourceMap ( inMap , map )
79+ }
7380 loaderContext . callback ( null , code , map )
7481}
7582
0 commit comments