Skip to content

Commit dd1439e

Browse files
committed
build: reduce runtime build size
1 parent 9d5dd2d commit dd1439e

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

packages/runtime-core/__tests__/hmr.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { baseCompile } from '@vue/compiler-core'
1616
declare var __VUE_HMR_RUNTIME__: HMRRuntime
1717
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
1818

19+
runtimeTest.registerRuntimeCompiler(compileToFunction)
20+
1921
function compileToFunction(template: string) {
2022
const { code } = baseCompile(template)
2123
const render = new Function('Vue', code)(

packages/runtime-core/src/component.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
import {
1111
ComponentPublicInstance,
1212
PublicInstanceProxyHandlers,
13-
RuntimeCompiledPublicInstanceProxyHandlers,
1413
createRenderContext,
1514
exposePropsOnRenderContext,
1615
exposeSetupStateOnRenderContext,
1716
ComponentPublicInstanceConstructor,
18-
publicPropertiesMap
17+
publicPropertiesMap,
18+
RuntimeCompiledPublicInstanceProxyHandlers
1919
} from './componentPublicInstance'
2020
import {
2121
ComponentPropsOptions,
@@ -711,18 +711,24 @@ type CompileFunction = (
711711
) => InternalRenderFunction
712712

713713
let compile: CompileFunction | undefined
714-
715-
// dev only
716-
export const isRuntimeOnly = () => !compile
714+
let installWithProxy: (i: ComponentInternalInstance) => void
717715

718716
/**
719717
* For runtime-dom to register the compiler.
720718
* Note the exported method uses any to avoid d.ts relying on the compiler types.
721719
*/
722720
export function registerRuntimeCompiler(_compile: any) {
723721
compile = _compile
722+
installWithProxy = i => {
723+
if (i.render!._rc) {
724+
i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers)
725+
}
726+
}
724727
}
725728

729+
// dev only
730+
export const isRuntimeOnly = () => !compile
731+
726732
export function finishComponentSetup(
727733
instance: ComponentInternalInstance,
728734
isSSR: boolean,
@@ -792,11 +798,8 @@ export function finishComponentSetup(
792798
// for runtime-compiled render functions using `with` blocks, the render
793799
// proxy used needs a different `has` handler which is more performant and
794800
// also only allows a whitelist of globals to fallthrough.
795-
if (instance.render._rc) {
796-
instance.withProxy = new Proxy(
797-
instance.ctx,
798-
RuntimeCompiledPublicInstanceProxyHandlers
799-
)
801+
if (installWithProxy) {
802+
installWithProxy(instance)
800803
}
801804
}
802805

packages/runtime-core/src/componentPublicInstance.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const getPublicInstance = (
224224
return getPublicInstance(i.parent)
225225
}
226226

227-
export const publicPropertiesMap: PublicPropertiesMap = extend(
227+
export const publicPropertiesMap: PublicPropertiesMap = /*#__PURE__*/ extend(
228228
Object.create(null),
229229
{
230230
$: i => i,
@@ -459,7 +459,7 @@ if (__DEV__ && !__TEST__) {
459459
}
460460
}
461461

462-
export const RuntimeCompiledPublicInstanceProxyHandlers = extend(
462+
export const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend(
463463
{},
464464
PublicInstanceProxyHandlers,
465465
{

0 commit comments

Comments
 (0)