feat(compiler-sfc): allow disabling sourcemap when not needed
This commit is contained in:
parent
ebe00f66dd
commit
585615beb1
@ -77,6 +77,10 @@ export interface SFCScriptCompileOptions {
|
|||||||
* Production mode. Used to determine whether to generate hashed CSS variables
|
* Production mode. Used to determine whether to generate hashed CSS variables
|
||||||
*/
|
*/
|
||||||
isProd?: boolean
|
isProd?: boolean
|
||||||
|
/**
|
||||||
|
* Enable/disable source map. Defaults to true.
|
||||||
|
*/
|
||||||
|
sourceMap?: boolean
|
||||||
/**
|
/**
|
||||||
* https://babeljs.io/docs/en/babel-parser#plugins
|
* https://babeljs.io/docs/en/babel-parser#plugins
|
||||||
*/
|
*/
|
||||||
@ -127,12 +131,9 @@ export function compileScript(
|
|||||||
let { script, scriptSetup, source, filename } = sfc
|
let { script, scriptSetup, source, filename } = sfc
|
||||||
// feature flags
|
// feature flags
|
||||||
const enableRefTransform = !!options.refSugar || !!options.refTransform
|
const enableRefTransform = !!options.refSugar || !!options.refTransform
|
||||||
|
const genSourceMap = options.sourceMap !== false
|
||||||
let refBindings: string[] | undefined
|
let refBindings: string[] | undefined
|
||||||
|
|
||||||
// for backwards compat
|
|
||||||
if (!options) {
|
|
||||||
options = { id: '' }
|
|
||||||
}
|
|
||||||
if (!options.id) {
|
if (!options.id) {
|
||||||
warnOnce(
|
warnOnce(
|
||||||
`compileScript now requires passing the \`id\` option.\n` +
|
`compileScript now requires passing the \`id\` option.\n` +
|
||||||
@ -188,12 +189,14 @@ export function compileScript(
|
|||||||
s.remove(0, startOffset)
|
s.remove(0, startOffset)
|
||||||
s.remove(endOffset, source.length)
|
s.remove(endOffset, source.length)
|
||||||
content = s.toString()
|
content = s.toString()
|
||||||
|
if (genSourceMap) {
|
||||||
map = s.generateMap({
|
map = s.generateMap({
|
||||||
source: filename,
|
source: filename,
|
||||||
hires: true,
|
hires: true,
|
||||||
includeContent: true
|
includeContent: true
|
||||||
}) as unknown as RawSourceMap
|
}) as unknown as RawSourceMap
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (cssVars.length) {
|
if (cssVars.length) {
|
||||||
content = rewriteDefault(content, `__default__`, plugins)
|
content = rewriteDefault(content, `__default__`, plugins)
|
||||||
content += genNormalScriptCssVarsCode(
|
content += genNormalScriptCssVarsCode(
|
||||||
@ -1307,11 +1310,13 @@ export function compileScript(
|
|||||||
...scriptSetup,
|
...scriptSetup,
|
||||||
bindings: bindingMetadata,
|
bindings: bindingMetadata,
|
||||||
content: s.toString(),
|
content: s.toString(),
|
||||||
map: s.generateMap({
|
map: genSourceMap
|
||||||
|
? (s.generateMap({
|
||||||
source: filename,
|
source: filename,
|
||||||
hires: true,
|
hires: true,
|
||||||
includeContent: true
|
includeContent: true
|
||||||
}) as unknown as RawSourceMap,
|
}) as unknown as RawSourceMap)
|
||||||
|
: undefined,
|
||||||
scriptAst: scriptAst?.body,
|
scriptAst: scriptAst?.body,
|
||||||
scriptSetupAst: scriptSetupAst?.body
|
scriptSetupAst: scriptSetupAst?.body
|
||||||
}
|
}
|
||||||
|
@ -206,10 +206,10 @@ function doCompileTemplate({
|
|||||||
: '',
|
: '',
|
||||||
scopeId: scoped ? longId : undefined,
|
scopeId: scoped ? longId : undefined,
|
||||||
slotted,
|
slotted,
|
||||||
|
sourceMap: true,
|
||||||
...compilerOptions,
|
...compilerOptions,
|
||||||
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
|
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
|
||||||
filename,
|
filename,
|
||||||
sourceMap: true,
|
|
||||||
onError: e => errors.push(e),
|
onError: e => errors.push(e),
|
||||||
onWarn: w => warnings.push(w)
|
onWarn: w => warnings.push(w)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user