build: avoid runtime wildcard import in global build

This commit is contained in:
Evan You 2020-02-13 18:50:36 -05:00
parent 5455e8e69a
commit 32d6a46474
4 changed files with 12 additions and 1 deletions

View File

@ -7,6 +7,7 @@ module.exports = {
__BROWSER__: false, __BROWSER__: false,
__BUNDLER__: true, __BUNDLER__: true,
__RUNTIME_COMPILE__: true, __RUNTIME_COMPILE__: true,
__GLOBAL__: false,
__NODE_JS__: true, __NODE_JS__: true,
__FEATURE_OPTIONS__: true, __FEATURE_OPTIONS__: true,
__FEATURE_SUSPENSE__: true __FEATURE_SUSPENSE__: true

View File

@ -4,6 +4,7 @@ declare var __TEST__: boolean
declare var __BROWSER__: boolean declare var __BROWSER__: boolean
declare var __BUNDLER__: boolean declare var __BUNDLER__: boolean
declare var __RUNTIME_COMPILE__: boolean declare var __RUNTIME_COMPILE__: boolean
declare var __GLOBAL__: boolean
declare var __NODE_JS__: boolean declare var __NODE_JS__: boolean
declare var __COMMIT__: string declare var __COMMIT__: string
declare var __VERSION__: string declare var __VERSION__: string

View File

@ -58,7 +58,13 @@ function compileToFunction(
...options ...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) return (compileCache[key] = render)
} }

View File

@ -136,6 +136,7 @@ function createConfig(format, output, plugins = []) {
(isGlobalBuild || isRawESMBuild || isBundlerESMBuild) && (isGlobalBuild || isRawESMBuild || isBundlerESMBuild) &&
!packageOptions.enableNonBrowserBranches, !packageOptions.enableNonBrowserBranches,
isRuntimeCompileBuild, isRuntimeCompileBuild,
isGlobalBuild,
isNodeBuild isNodeBuild
), ),
...plugins ...plugins
@ -154,6 +155,7 @@ function createReplacePlugin(
isBundlerESMBuild, isBundlerESMBuild,
isBrowserBuild, isBrowserBuild,
isRuntimeCompileBuild, isRuntimeCompileBuild,
isGlobalBuild,
isNodeBuild isNodeBuild
) { ) {
const replacements = { const replacements = {
@ -172,6 +174,7 @@ function createReplacePlugin(
__BUNDLER__: isBundlerESMBuild, __BUNDLER__: isBundlerESMBuild,
// support compile in browser? // support compile in browser?
__RUNTIME_COMPILE__: isRuntimeCompileBuild, __RUNTIME_COMPILE__: isRuntimeCompileBuild,
__GLOBAL__: isGlobalBuild,
// is targeting Node (SSR)? // is targeting Node (SSR)?
__NODE_JS__: isNodeBuild, __NODE_JS__: isNodeBuild,
// support options? // support options?