@@ -77,6 +77,10 @@ export interface SFCScriptCompileOptions {
77
77
* Production mode. Used to determine whether to generate hashed CSS variables
78
78
*/
79
79
isProd ?: boolean
80
+ /**
81
+ * Enable/disable source map. Defaults to true.
82
+ */
83
+ sourceMap ?: boolean
80
84
/**
81
85
* https://babeljs.io/docs/en/babel-parser#plugins
82
86
*/
@@ -127,12 +131,9 @@ export function compileScript(
127
131
let { script, scriptSetup, source, filename } = sfc
128
132
// feature flags
129
133
const enableRefTransform = ! ! options . refSugar || ! ! options . refTransform
134
+ const genSourceMap = options . sourceMap !== false
130
135
let refBindings : string [ ] | undefined
131
136
132
- // for backwards compat
133
- if ( ! options ) {
134
- options = { id : '' }
135
- }
136
137
if ( ! options . id ) {
137
138
warnOnce (
138
139
`compileScript now requires passing the \`id\` option.\n` +
@@ -188,11 +189,13 @@ export function compileScript(
188
189
s . remove ( 0 , startOffset )
189
190
s . remove ( endOffset , source . length )
190
191
content = s . toString ( )
191
- map = s . generateMap ( {
192
- source : filename ,
193
- hires : true ,
194
- includeContent : true
195
- } ) as unknown as RawSourceMap
192
+ if ( genSourceMap ) {
193
+ map = s . generateMap ( {
194
+ source : filename ,
195
+ hires : true ,
196
+ includeContent : true
197
+ } ) as unknown as RawSourceMap
198
+ }
196
199
}
197
200
if ( cssVars . length ) {
198
201
content = rewriteDefault ( content , `__default__` , plugins )
@@ -1307,11 +1310,13 @@ export function compileScript(
1307
1310
...scriptSetup ,
1308
1311
bindings : bindingMetadata ,
1309
1312
content : s . toString ( ) ,
1310
- map : s . generateMap ( {
1311
- source : filename ,
1312
- hires : true ,
1313
- includeContent : true
1314
- } ) as unknown as RawSourceMap ,
1313
+ map : genSourceMap
1314
+ ? ( s . generateMap ( {
1315
+ source : filename ,
1316
+ hires : true ,
1317
+ includeContent : true
1318
+ } ) as unknown as RawSourceMap )
1319
+ : undefined ,
1315
1320
scriptAst : scriptAst ?. body ,
1316
1321
scriptSetupAst : scriptSetupAst ?. body
1317
1322
}
0 commit comments