Skip to content

Commit

Permalink
feat(compiler-sfc): allow disabling sourcemap when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 18, 2021
1 parent ebe00f6 commit 585615b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 19 additions & 14 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export interface SFCScriptCompileOptions {
* Production mode. Used to determine whether to generate hashed CSS variables
*/
isProd?: boolean
/**
* Enable/disable source map. Defaults to true.
*/
sourceMap?: boolean
/**
* https://babeljs.io/docs/en/babel-parser#plugins
*/
Expand Down Expand Up @@ -127,12 +131,9 @@ export function compileScript(
let { script, scriptSetup, source, filename } = sfc
// feature flags
const enableRefTransform = !!options.refSugar || !!options.refTransform
const genSourceMap = options.sourceMap !== false
let refBindings: string[] | undefined

// for backwards compat
if (!options) {
options = { id: '' }
}
if (!options.id) {
warnOnce(
`compileScript now requires passing the \`id\` option.\n` +
Expand Down Expand Up @@ -188,11 +189,13 @@ export function compileScript(
s.remove(0, startOffset)
s.remove(endOffset, source.length)
content = s.toString()
map = s.generateMap({
source: filename,
hires: true,
includeContent: true
}) as unknown as RawSourceMap
if (genSourceMap) {
map = s.generateMap({
source: filename,
hires: true,
includeContent: true
}) as unknown as RawSourceMap
}
}
if (cssVars.length) {
content = rewriteDefault(content, `__default__`, plugins)
Expand Down Expand Up @@ -1307,11 +1310,13 @@ export function compileScript(
...scriptSetup,
bindings: bindingMetadata,
content: s.toString(),
map: s.generateMap({
source: filename,
hires: true,
includeContent: true
}) as unknown as RawSourceMap,
map: genSourceMap
? (s.generateMap({
source: filename,
hires: true,
includeContent: true
}) as unknown as RawSourceMap)
: undefined,
scriptAst: scriptAst?.body,
scriptSetupAst: scriptSetupAst?.body
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ function doCompileTemplate({
: '',
scopeId: scoped ? longId : undefined,
slotted,
sourceMap: true,
...compilerOptions,
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
filename,
sourceMap: true,
onError: e => errors.push(e),
onWarn: w => warnings.push(w)
})
Expand Down

0 comments on commit 585615b

Please sign in to comment.