build: further shave off runtime compile only code
This commit is contained in:
parent
57a94b530d
commit
82b5978e9c
@ -4,6 +4,7 @@ module.exports = {
|
|||||||
__DEV__: true,
|
__DEV__: true,
|
||||||
__BROWSER__: false,
|
__BROWSER__: false,
|
||||||
__JSDOM__: true,
|
__JSDOM__: true,
|
||||||
|
__RUNTIME_COMPILE__: true,
|
||||||
__FEATURE_OPTIONS__: true,
|
__FEATURE_OPTIONS__: true,
|
||||||
__FEATURE_SUSPENSE__: true
|
__FEATURE_SUSPENSE__: true
|
||||||
},
|
},
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node scripts/dev.js",
|
||||||
"build": "node scripts/build.js",
|
"build": "node scripts/build.js",
|
||||||
"size-runtime": "node scripts/build.js runtime-dom -p -f esm-browser",
|
"size-runtime": "node scripts/build.js runtime-dom -p -f global",
|
||||||
"size-compiler": "node scripts/build.js compiler-dom -p -f esm-browser",
|
"size-compiler": "node scripts/build.js compiler-dom -p -f global",
|
||||||
"size": "yarn size-runtime && yarn size-compiler",
|
"size": "yarn size-runtime && yarn size-compiler",
|
||||||
"lint": "prettier --write --parser typescript 'packages/**/*.ts'",
|
"lint": "prettier --write --parser typescript 'packages/**/*.ts'",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
|
1
packages/global.d.ts
vendored
1
packages/global.d.ts
vendored
@ -2,6 +2,7 @@
|
|||||||
declare var __DEV__: boolean
|
declare var __DEV__: boolean
|
||||||
declare var __JSDOM__: boolean
|
declare var __JSDOM__: boolean
|
||||||
declare var __BROWSER__: boolean
|
declare var __BROWSER__: boolean
|
||||||
|
declare var __RUNTIME_COMPILE__: boolean
|
||||||
declare var __COMMIT__: string
|
declare var __COMMIT__: string
|
||||||
|
|
||||||
// Feature flags
|
// Feature flags
|
||||||
|
@ -320,7 +320,7 @@ function finishComponentSetup(
|
|||||||
) {
|
) {
|
||||||
const Component = instance.type as ComponentOptions
|
const Component = instance.type as ComponentOptions
|
||||||
if (!instance.render) {
|
if (!instance.render) {
|
||||||
if (Component.template && !Component.render) {
|
if (__RUNTIME_COMPILE__ && Component.template && !Component.render) {
|
||||||
if (compile) {
|
if (compile) {
|
||||||
Component.render = compile(Component.template, {
|
Component.render = compile(Component.template, {
|
||||||
onError(err: CompilerError) {
|
onError(err: CompilerError) {
|
||||||
|
@ -48,7 +48,7 @@ const publicPropertiesMap = {
|
|||||||
$options: 'type'
|
$options: 'type'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PublicInstanceProxyHandlers = {
|
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
||||||
get(target: ComponentInternalInstance, key: string) {
|
get(target: ComponentInternalInstance, key: string) {
|
||||||
const { renderContext, data, props, propsProxy } = target
|
const { renderContext, data, props, propsProxy } = target
|
||||||
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||||||
@ -76,11 +76,7 @@ export const PublicInstanceProxyHandlers = {
|
|||||||
}
|
}
|
||||||
return target.user[key]
|
return target.user[key]
|
||||||
},
|
},
|
||||||
// this trap is only called in browser-compiled render functions that use
|
|
||||||
// `with (this) {}`
|
|
||||||
has(_: any, key: string): boolean {
|
|
||||||
return key[0] !== '_' && !globalsWhitelist.has(key)
|
|
||||||
},
|
|
||||||
set(target: ComponentInternalInstance, key: string, value: any): boolean {
|
set(target: ComponentInternalInstance, key: string, value: any): boolean {
|
||||||
const { data, renderContext } = target
|
const { data, renderContext } = target
|
||||||
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||||||
@ -105,3 +101,11 @@ export const PublicInstanceProxyHandlers = {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (__RUNTIME_COMPILE__) {
|
||||||
|
// this trap is only called in browser-compiled render functions that use
|
||||||
|
// `with (this) {}`
|
||||||
|
PublicInstanceProxyHandlers.has = (_: any, key: string): boolean => {
|
||||||
|
return key[0] !== '_' && !globalsWhitelist.has(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -76,6 +76,7 @@ function createConfig(output, plugins = []) {
|
|||||||
const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
|
const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
|
||||||
const isBundlerESMBuild = /\.esm\.js$/.test(output.file)
|
const isBundlerESMBuild = /\.esm\.js$/.test(output.file)
|
||||||
const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file)
|
const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file)
|
||||||
|
const isRuntimeCompileBuild = /^dist\/vue\./.test(output.file)
|
||||||
|
|
||||||
if (isGlobalBuild) {
|
if (isGlobalBuild) {
|
||||||
output.name = packageOptions.name
|
output.name = packageOptions.name
|
||||||
@ -120,7 +121,8 @@ function createConfig(output, plugins = []) {
|
|||||||
isProductionBuild,
|
isProductionBuild,
|
||||||
isBundlerESMBuild,
|
isBundlerESMBuild,
|
||||||
(isGlobalBuild || isBrowserESMBuild) &&
|
(isGlobalBuild || isBrowserESMBuild) &&
|
||||||
!packageOptions.enableNonBrowserBranches
|
!packageOptions.enableNonBrowserBranches,
|
||||||
|
isRuntimeCompileBuild
|
||||||
),
|
),
|
||||||
...plugins
|
...plugins
|
||||||
],
|
],
|
||||||
@ -133,7 +135,12 @@ function createConfig(output, plugins = []) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createReplacePlugin(isProduction, isBundlerESMBuild, isBrowserBuild) {
|
function createReplacePlugin(
|
||||||
|
isProduction,
|
||||||
|
isBundlerESMBuild,
|
||||||
|
isBrowserBuild,
|
||||||
|
isRuntimeCompileBuild
|
||||||
|
) {
|
||||||
return replace({
|
return replace({
|
||||||
__COMMIT__: `"${process.env.COMMIT}"`,
|
__COMMIT__: `"${process.env.COMMIT}"`,
|
||||||
__DEV__: isBundlerESMBuild
|
__DEV__: isBundlerESMBuild
|
||||||
@ -143,9 +150,11 @@ function createReplacePlugin(isProduction, isBundlerESMBuild, isBrowserBuild) {
|
|||||||
!isProduction,
|
!isProduction,
|
||||||
// If the build is expected to run directly in the browser (global / esm-browser builds)
|
// If the build is expected to run directly in the browser (global / esm-browser builds)
|
||||||
__BROWSER__: isBrowserBuild,
|
__BROWSER__: isBrowserBuild,
|
||||||
|
// support compile in browser?
|
||||||
|
__RUNTIME_COMPILE__: isRuntimeCompileBuild,
|
||||||
// support options?
|
// support options?
|
||||||
// the lean build drops options related code with buildOptions.lean: true
|
// the lean build drops options related code with buildOptions.lean: true
|
||||||
__FEATURE_OPTIONS__: !packageOptions.lean,
|
__FEATURE_OPTIONS__: !packageOptions.lean && !process.env.LEAN,
|
||||||
__FEATURE_SUSPENSE__: true,
|
__FEATURE_SUSPENSE__: true,
|
||||||
// this is only used during tests
|
// this is only used during tests
|
||||||
__JSDOM__: false
|
__JSDOM__: false
|
||||||
|
@ -28,8 +28,12 @@ const formats = args.formats || args.f
|
|||||||
const devOnly = args.devOnly || args.d
|
const devOnly = args.devOnly || args.d
|
||||||
const prodOnly = !devOnly && (args.prodOnly || args.p)
|
const prodOnly = !devOnly && (args.prodOnly || args.p)
|
||||||
const buildAllMatching = args.all || args.a
|
const buildAllMatching = args.all || args.a
|
||||||
|
const lean = args.lean || args.l
|
||||||
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
|
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
|
||||||
;(async () => {
|
|
||||||
|
run()
|
||||||
|
|
||||||
|
async function run() {
|
||||||
if (!targets.length) {
|
if (!targets.length) {
|
||||||
await buildAll(allTargets)
|
await buildAll(allTargets)
|
||||||
checkAllSizes(allTargets)
|
checkAllSizes(allTargets)
|
||||||
@ -37,7 +41,7 @@ const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
|
|||||||
await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
|
await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
|
||||||
checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
|
checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
|
||||||
}
|
}
|
||||||
})()
|
}
|
||||||
|
|
||||||
async function buildAll(targets) {
|
async function buildAll(targets) {
|
||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
@ -54,7 +58,6 @@ async function build(target) {
|
|||||||
const env =
|
const env =
|
||||||
(pkg.buildOptions && pkg.buildOptions.env) ||
|
(pkg.buildOptions && pkg.buildOptions.env) ||
|
||||||
(devOnly ? 'development' : 'production')
|
(devOnly ? 'development' : 'production')
|
||||||
|
|
||||||
await execa(
|
await execa(
|
||||||
'rollup',
|
'rollup',
|
||||||
[
|
[
|
||||||
@ -66,7 +69,8 @@ async function build(target) {
|
|||||||
`TARGET:${target}`,
|
`TARGET:${target}`,
|
||||||
formats ? `FORMATS:${formats}` : ``,
|
formats ? `FORMATS:${formats}` : ``,
|
||||||
args.types ? `TYPES:true` : ``,
|
args.types ? `TYPES:true` : ``,
|
||||||
prodOnly ? `PROD_ONLY:true` : ``
|
prodOnly ? `PROD_ONLY:true` : ``,
|
||||||
|
lean ? `LEAN:true` : ``
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(',')
|
.join(',')
|
||||||
@ -118,7 +122,7 @@ function checkAllSizes(targets) {
|
|||||||
|
|
||||||
function checkSize(target) {
|
function checkSize(target) {
|
||||||
const pkgDir = path.resolve(`packages/${target}`)
|
const pkgDir = path.resolve(`packages/${target}`)
|
||||||
const esmProdBuild = `${pkgDir}/dist/${target}.esm-browser.prod.js`
|
const esmProdBuild = `${pkgDir}/dist/${target}.global.prod.js`
|
||||||
if (fs.existsSync(esmProdBuild)) {
|
if (fs.existsSync(esmProdBuild)) {
|
||||||
const file = fs.readFileSync(esmProdBuild)
|
const file = fs.readFileSync(esmProdBuild)
|
||||||
const minSize = (file.length / 1024).toFixed(2) + 'kb'
|
const minSize = (file.length / 1024).toFixed(2) + 'kb'
|
||||||
|
Loading…
Reference in New Issue
Block a user