Skip to content

Commit 585615b

Browse files
committed
feat(compiler-sfc): allow disabling sourcemap when not needed
1 parent ebe00f6 commit 585615b

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

packages/compiler-sfc/src/compileScript.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export interface SFCScriptCompileOptions {
7777
* Production mode. Used to determine whether to generate hashed CSS variables
7878
*/
7979
isProd?: boolean
80+
/**
81+
* Enable/disable source map. Defaults to true.
82+
*/
83+
sourceMap?: boolean
8084
/**
8185
* https://babeljs.io/docs/en/babel-parser#plugins
8286
*/
@@ -127,12 +131,9 @@ export function compileScript(
127131
let { script, scriptSetup, source, filename } = sfc
128132
// feature flags
129133
const enableRefTransform = !!options.refSugar || !!options.refTransform
134+
const genSourceMap = options.sourceMap !== false
130135
let refBindings: string[] | undefined
131136

132-
// for backwards compat
133-
if (!options) {
134-
options = { id: '' }
135-
}
136137
if (!options.id) {
137138
warnOnce(
138139
`compileScript now requires passing the \`id\` option.\n` +
@@ -188,11 +189,13 @@ export function compileScript(
188189
s.remove(0, startOffset)
189190
s.remove(endOffset, source.length)
190191
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+
}
196199
}
197200
if (cssVars.length) {
198201
content = rewriteDefault(content, `__default__`, plugins)
@@ -1307,11 +1310,13 @@ export function compileScript(
13071310
...scriptSetup,
13081311
bindings: bindingMetadata,
13091312
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,
13151320
scriptAst: scriptAst?.body,
13161321
scriptSetupAst: scriptSetupAst?.body
13171322
}

packages/compiler-sfc/src/compileTemplate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ function doCompileTemplate({
206206
: '',
207207
scopeId: scoped ? longId : undefined,
208208
slotted,
209+
sourceMap: true,
209210
...compilerOptions,
210211
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
211212
filename,
212-
sourceMap: true,
213213
onError: e => errors.push(e),
214214
onWarn: w => warnings.push(w)
215215
})

0 commit comments

Comments
 (0)