@@ -44,18 +44,22 @@ type PreprocessLang = SFCAsyncStyleCompileOptions['preprocessLang'];
44
44
* the version of the library
45
45
*/
46
46
import { version , vueVersion } from './index'
47
+ import { RawSourceMap } from '@vue/component-compiler-utils/dist/types'
47
48
48
49
// @ts -ignore
49
50
const targetBrowserBabelPluginsHash : string = hash ( ...Object . keys ( { ...( typeof ___targetBrowserBabelPlugins !== 'undefined' ? ___targetBrowserBabelPlugins : { } ) } ) ) ;
50
51
51
- const genSourcemap : boolean = ! ! process . env . GEN_SOURCEMAP ;
52
+ const genSourcemap : boolean | "inline" = process . env . GEN_SOURCEMAP ;
52
53
53
54
/**
54
55
* @internal
55
56
*/
56
57
const isProd : boolean = process . env . NODE_ENV === 'production' ;
57
58
58
-
59
+ /**
60
+ * @internal
61
+ */
62
+ const buildMapComment = ( map : RawSourceMap ) => `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${ btoa ( JSON . stringify ( map ) ) } `
59
63
60
64
/**
61
65
* @internal
@@ -87,7 +91,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
87
91
// vue-loader next: https://github.com/vuejs/vue-loader/blob/next/src/index.ts#L91
88
92
const { descriptor, errors } = sfc_parse ( source , {
89
93
filename : strFilename ,
90
- sourceMap : genSourcemap ,
94
+ sourceMap : ! ! genSourcemap ,
91
95
} ) ;
92
96
93
97
@@ -111,13 +115,14 @@ export async function createSFCModule(source : string, filename : AbstractPath,
111
115
112
116
const compileTemplateOptions : SFCTemplateCompileOptions | undefined = descriptor . template ? {
113
117
// hack, since sourceMap is not configurable an we want to get rid of source-map dependency. see genSourcemap
114
- compiler : { ...vue_CompilerDOM , compile : ( template , opts ) => vue_CompilerDOM . compile ( template , { ...opts , sourceMap : genSourcemap } ) } ,
118
+ compiler : { ...vue_CompilerDOM , compile : ( template , options ) => vue_CompilerDOM . compile ( template , { ...options , sourceMap : ! ! genSourcemap } ) } ,
115
119
source : descriptor . template . src ? ( await ( await getResource ( { refPath : filename , relPath : descriptor . template . src } , options ) . getContent ( ) ) . getContentData ( false ) ) as string : descriptor . template . content ,
116
120
filename : descriptor . filename ,
117
121
isProd,
118
122
scoped : hasScoped ,
119
123
id : scopeId ,
120
124
slotted : descriptor . slotted ,
125
+ inMap : descriptor . template . map ,
121
126
compilerOptions : {
122
127
isCustomElement,
123
128
whitespace,
@@ -170,7 +175,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
170
175
// src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileScript.ts#L43
171
176
const scriptBlock = sfc_compileScript ( descriptor , {
172
177
isProd,
173
- sourceMap : genSourcemap ,
178
+ sourceMap : ! ! genSourcemap ,
174
179
id : scopeId ,
175
180
// @ts -ignore (unstable resolution: node_modules/@babel/parser/typings/babel-parser vs node_modules/@types/babel__core/node_modules/@babel/parser/typings/babel-parser)
176
181
babelParserPlugins : [ ...contextBabelParserPlugins , ...additionalBabelParserPlugins ] , // [...babelParserDefaultPlugins, 'jsx'] + additionalBabelParserPlugins // babelParserDefaultPlugins = [ 'bigInt', 'optionalChaining', 'nullishCoalescingOperator' ]
@@ -180,6 +185,9 @@ export async function createSFCModule(source : string, filename : AbstractPath,
180
185
templateOptions : compileTemplateOptions ,
181
186
} ) ;
182
187
188
+ if ( scriptBlock . map )
189
+ scriptBlock . content += `\r\n${ buildMapComment ( scriptBlock . map ) } `
190
+
183
191
// note:
184
192
// scriptBlock.content is the script code after vue transformations
185
193
// scriptBlock.scriptAst is the script AST before vue transformations
@@ -192,7 +200,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
192
200
compileTemplateOptions . compilerOptions . bindingMetadata = bindingMetadata ;
193
201
194
202
await loadDeps ( filename , depsList , options ) ;
195
- Object . assign ( component , interopRequireDefault ( createCJSModule ( filename , transformedScriptSource , options ) . exports ) . default ) ;
203
+ Object . assign ( component , interopRequireDefault ( ( await createCJSModule ( filename , transformedScriptSource , options ) ) . exports ) . default ) ;
196
204
}
197
205
198
206
@@ -237,11 +245,14 @@ export async function createSFCModule(source : string, filename : AbstractPath,
237
245
for ( const err of template . tips )
238
246
log ?.( 'info' , 'SFC template' , err ) ;
239
247
248
+ if ( template . map )
249
+ template . code += `\r\n${ buildMapComment ( template . map ) } `
250
+
240
251
return await transformJSCode ( template . code , true , descriptor . filename , additionalBabelParserPlugins , additionalBabelPlugins , log , devMode ) ;
241
252
} ) ;
242
253
243
254
await loadDeps ( filename , templateDepsList , options ) ;
244
- Object . assign ( component , createCJSModule ( filename , templateTransformedSource , options ) . exports ) ;
255
+ Object . assign ( component , ( await createCJSModule ( filename , templateTransformedSource , options ) ) . exports ) ;
245
256
}
246
257
247
258
0 commit comments