]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: avoid runtime wildcard import in global build
authorEvan You <yyx990803@gmail.com>
Thu, 13 Feb 2020 23:50:36 +0000 (18:50 -0500)
committerEvan You <yyx990803@gmail.com>
Thu, 13 Feb 2020 23:50:36 +0000 (18:50 -0500)
jest.config.js
packages/global.d.ts
packages/vue/src/index.ts
rollup.config.js

index ebc6e76eb39be595255f3a307ffb3699e53480d1..aeda080216d85ea6fab76db32631a893e5d72de3 100644 (file)
@@ -7,6 +7,7 @@ module.exports = {
     __BROWSER__: false,
     __BUNDLER__: true,
     __RUNTIME_COMPILE__: true,
+    __GLOBAL__: false,
     __NODE_JS__: true,
     __FEATURE_OPTIONS__: true,
     __FEATURE_SUSPENSE__: true
index 7d1805539c86ba5598dc9bdb7afa9c26a670ac3b..3f644c9f6127b1e3f07302de4e2d3fcbf2fd5501 100644 (file)
@@ -4,6 +4,7 @@ declare var __TEST__: boolean
 declare var __BROWSER__: boolean
 declare var __BUNDLER__: boolean
 declare var __RUNTIME_COMPILE__: boolean
+declare var __GLOBAL__: boolean
 declare var __NODE_JS__: boolean
 declare var __COMMIT__: string
 declare var __VERSION__: string
index 085a5b34c2da3b94e0ab5f97817cff045f8152dc..056fcc90cc03e53baf401de79155ef0ce10509d3 100644 (file)
@@ -58,7 +58,13 @@ function compileToFunction(
     ...options
   })
 
-  const render = new Function('Vue', code)(runtimeDom) as RenderFunction
+  // The wildcard import results in a huge object with every export
+  // with keys that cannot be mangled, and can be quite heavy size-wise.
+  // In the global build we know `Vue` is available globally so we can avoid
+  // the wildcard object.
+  const render = (__GLOBAL__
+    ? new Function(code)()
+    : new Function('Vue', code)(runtimeDom)) as RenderFunction
   return (compileCache[key] = render)
 }
 
index 0934ba8bd6e7e58585b16bc3db451cfd46ff209d..18fc0e5aad525d3a863697d894ed289fd7df46ec 100644 (file)
@@ -136,6 +136,7 @@ function createConfig(format, output, plugins = []) {
         (isGlobalBuild || isRawESMBuild || isBundlerESMBuild) &&
           !packageOptions.enableNonBrowserBranches,
         isRuntimeCompileBuild,
+        isGlobalBuild,
         isNodeBuild
       ),
       ...plugins
@@ -154,6 +155,7 @@ function createReplacePlugin(
   isBundlerESMBuild,
   isBrowserBuild,
   isRuntimeCompileBuild,
+  isGlobalBuild,
   isNodeBuild
 ) {
   const replacements = {
@@ -172,6 +174,7 @@ function createReplacePlugin(
     __BUNDLER__: isBundlerESMBuild,
     // support compile in browser?
     __RUNTIME_COMPILE__: isRuntimeCompileBuild,
+    __GLOBAL__: isGlobalBuild,
     // is targeting Node (SSR)?
     __NODE_JS__: isNodeBuild,
     // support options?