build: reduce runtime build size

This commit is contained in:
Evan You 2021-07-21 11:11:40 -04:00
parent 9d5dd2da8c
commit dd1439e711
3 changed files with 17 additions and 12 deletions

View File

@ -16,6 +16,8 @@ import { baseCompile } from '@vue/compiler-core'
declare var __VUE_HMR_RUNTIME__: HMRRuntime declare var __VUE_HMR_RUNTIME__: HMRRuntime
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__ const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
runtimeTest.registerRuntimeCompiler(compileToFunction)
function compileToFunction(template: string) { function compileToFunction(template: string) {
const { code } = baseCompile(template) const { code } = baseCompile(template)
const render = new Function('Vue', code)( const render = new Function('Vue', code)(

View File

@ -10,12 +10,12 @@ import {
import { import {
ComponentPublicInstance, ComponentPublicInstance,
PublicInstanceProxyHandlers, PublicInstanceProxyHandlers,
RuntimeCompiledPublicInstanceProxyHandlers,
createRenderContext, createRenderContext,
exposePropsOnRenderContext, exposePropsOnRenderContext,
exposeSetupStateOnRenderContext, exposeSetupStateOnRenderContext,
ComponentPublicInstanceConstructor, ComponentPublicInstanceConstructor,
publicPropertiesMap publicPropertiesMap,
RuntimeCompiledPublicInstanceProxyHandlers
} from './componentPublicInstance' } from './componentPublicInstance'
import { import {
ComponentPropsOptions, ComponentPropsOptions,
@ -711,9 +711,7 @@ type CompileFunction = (
) => InternalRenderFunction ) => InternalRenderFunction
let compile: CompileFunction | undefined let compile: CompileFunction | undefined
let installWithProxy: (i: ComponentInternalInstance) => void
// dev only
export const isRuntimeOnly = () => !compile
/** /**
* For runtime-dom to register the compiler. * For runtime-dom to register the compiler.
@ -721,8 +719,16 @@ export const isRuntimeOnly = () => !compile
*/ */
export function registerRuntimeCompiler(_compile: any) { export function registerRuntimeCompiler(_compile: any) {
compile = _compile compile = _compile
installWithProxy = i => {
if (i.render!._rc) {
i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers)
}
}
} }
// dev only
export const isRuntimeOnly = () => !compile
export function finishComponentSetup( export function finishComponentSetup(
instance: ComponentInternalInstance, instance: ComponentInternalInstance,
isSSR: boolean, isSSR: boolean,
@ -792,11 +798,8 @@ export function finishComponentSetup(
// for runtime-compiled render functions using `with` blocks, the render // for runtime-compiled render functions using `with` blocks, the render
// proxy used needs a different `has` handler which is more performant and // proxy used needs a different `has` handler which is more performant and
// also only allows a whitelist of globals to fallthrough. // also only allows a whitelist of globals to fallthrough.
if (instance.render._rc) { if (installWithProxy) {
instance.withProxy = new Proxy( installWithProxy(instance)
instance.ctx,
RuntimeCompiledPublicInstanceProxyHandlers
)
} }
} }

View File

@ -224,7 +224,7 @@ const getPublicInstance = (
return getPublicInstance(i.parent) return getPublicInstance(i.parent)
} }
export const publicPropertiesMap: PublicPropertiesMap = extend( export const publicPropertiesMap: PublicPropertiesMap = /*#__PURE__*/ extend(
Object.create(null), Object.create(null),
{ {
$: i => i, $: i => i,
@ -459,7 +459,7 @@ if (__DEV__ && !__TEST__) {
} }
} }
export const RuntimeCompiledPublicInstanceProxyHandlers = extend( export const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend(
{}, {},
PublicInstanceProxyHandlers, PublicInstanceProxyHandlers,
{ {