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
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
runtimeTest.registerRuntimeCompiler(compileToFunction)
function compileToFunction(template: string) {
const { code } = baseCompile(template)
const render = new Function('Vue', code)(

View File

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

View File

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