]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler-sfc): allow disabling sourcemap when not needed
authorEvan You <yyx990803@gmail.com>
Sat, 18 Sep 2021 21:42:09 +0000 (17:42 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 18 Sep 2021 21:42:09 +0000 (17:42 -0400)
packages/compiler-sfc/src/compileScript.ts
packages/compiler-sfc/src/compileTemplate.ts

index 253abbaed141df1f775d02154f68057c1b4ba169..440c013d8640c40510e34f22cad3aaf15e759983 100644 (file)
@@ -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
    */
@@ -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` +
@@ -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)
@@ -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
   }
index 4e54942a21813a441197f4c44312df24a22f9e67..6f44616d4eefe68d7fc8912cd312ded2cb5584e1 100644 (file)
@@ -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)
   })