@@ -44,18 +44,22 @@ type PreprocessLang = SFCAsyncStyleCompileOptions['preprocessLang'];
4444 * the version of the library
4545 */
4646import { version , vueVersion } from './index'
47+ import { RawSourceMap } from '@vue/component-compiler-utils/dist/types'
4748
4849// @ts -ignore
4950const targetBrowserBabelPluginsHash : string = hash ( ...Object . keys ( { ...( typeof ___targetBrowserBabelPlugins !== 'undefined' ? ___targetBrowserBabelPlugins : { } ) } ) ) ;
5051
51- const genSourcemap : boolean = ! ! process . env . GEN_SOURCEMAP ;
52+ const genSourcemap : boolean | "inline" = process . env . GEN_SOURCEMAP ;
5253
5354/**
5455 * @internal
5556 */
5657const isProd : boolean = process . env . NODE_ENV === 'production' ;
5758
58-
59+ /**
60+ * @internal
61+ */
62+ const buildMapComment = ( map : RawSourceMap ) => `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${ btoa ( JSON . stringify ( map ) ) } `
5963
6064/**
6165 * @internal
@@ -87,7 +91,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
8791 // vue-loader next: https://github.com/vuejs/vue-loader/blob/next/src/index.ts#L91
8892 const { descriptor, errors } = sfc_parse ( source , {
8993 filename : strFilename ,
90- sourceMap : genSourcemap ,
94+ sourceMap : ! ! genSourcemap ,
9195 } ) ;
9296
9397
@@ -111,13 +115,14 @@ export async function createSFCModule(source : string, filename : AbstractPath,
111115
112116 const compileTemplateOptions : SFCTemplateCompileOptions | undefined = descriptor . template ? {
113117 // hack, since sourceMap is not configurable an we want to get rid of source-map dependency. see genSourcemap
114- compiler : { ...vue_CompilerDOM , compile : ( template , options ) => vue_CompilerDOM . compile ( template , { ...options , sourceMap : genSourcemap } ) } ,
118+ compiler : { ...vue_CompilerDOM , compile : ( template , options ) => vue_CompilerDOM . compile ( template , { ...options , sourceMap : ! ! genSourcemap } ) } ,
115119 source : descriptor . template . src ? ( await ( await getResource ( { refPath : filename , relPath : descriptor . template . src } , options ) . getContent ( ) ) . getContentData ( false ) ) as string : descriptor . template . content ,
116120 filename : descriptor . filename ,
117121 isProd,
118122 scoped : hasScoped ,
119123 id : scopeId ,
120124 slotted : descriptor . slotted ,
125+ inMap : descriptor . template . map ,
121126 compilerOptions : {
122127 isCustomElement,
123128 whitespace,
@@ -170,7 +175,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
170175 // src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileScript.ts#L43
171176 const scriptBlock = sfc_compileScript ( descriptor , {
172177 isProd,
173- sourceMap : genSourcemap ,
178+ sourceMap : ! ! genSourcemap ,
174179 id : scopeId ,
175180 // @ts -ignore (unstable resolution: node_modules/@babel/parser/typings/babel-parser vs node_modules/@types/babel__core/node_modules/@babel/parser/typings/babel-parser)
176181 babelParserPlugins : [ ...contextBabelParserPlugins , ...additionalBabelParserPlugins ] , // [...babelParserDefaultPlugins, 'jsx'] + additionalBabelParserPlugins // babelParserDefaultPlugins = [ 'bigInt', 'optionalChaining', 'nullishCoalescingOperator' ]
@@ -180,6 +185,9 @@ export async function createSFCModule(source : string, filename : AbstractPath,
180185 templateOptions : compileTemplateOptions ,
181186 } ) ;
182187
188+ if ( scriptBlock . map )
189+ scriptBlock . content += `\r\n${ buildMapComment ( scriptBlock . map ) } `
190+
183191 // note:
184192 // scriptBlock.content is the script code after vue transformations
185193 // scriptBlock.scriptAst is the script AST before vue transformations
@@ -192,7 +200,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
192200 compileTemplateOptions . compilerOptions . bindingMetadata = bindingMetadata ;
193201
194202 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 ) ;
196204 }
197205
198206
@@ -237,11 +245,14 @@ export async function createSFCModule(source : string, filename : AbstractPath,
237245 for ( const err of template . tips )
238246 log ?.( 'info' , 'SFC template' , err ) ;
239247
248+ if ( template . map )
249+ template . code += `\r\n${ buildMapComment ( template . map ) } `
250+
240251 return await transformJSCode ( template . code , true , descriptor . filename , additionalBabelParserPlugins , additionalBabelPlugins , log , devMode ) ;
241252 } ) ;
242253
243254 await loadDeps ( filename , templateDepsList , options ) ;
244- Object . assign ( component , createCJSModule ( filename , templateTransformedSource , options ) . exports ) ;
255+ Object . assign ( component , ( await createCJSModule ( filename , templateTransformedSource , options ) ) . exports ) ;
245256 }
246257
247258
0 commit comments