]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: further shave off runtime compile only code
authorEvan You <yyx990803@gmail.com>
Mon, 14 Oct 2019 05:08:00 +0000 (01:08 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 14 Oct 2019 05:08:00 +0000 (01:08 -0400)
jest.config.js
package.json
packages/global.d.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/componentProxy.ts
rollup.config.js
scripts/build.js

index fc8cb8e40e7b406bbca765f832c893dbfe92582e..f1147e27f18b789cd11a800a803c3477322c0881 100644 (file)
@@ -4,6 +4,7 @@ module.exports = {
     __DEV__: true,
     __BROWSER__: false,
     __JSDOM__: true,
+    __RUNTIME_COMPILE__: true,
     __FEATURE_OPTIONS__: true,
     __FEATURE_SUSPENSE__: true
   },
index b83d4927c9ce3d3468980f6881683b2b2c97d1ba..d0f6d316a4970201770276275ee2b9fef8179132 100644 (file)
@@ -6,8 +6,8 @@
   "scripts": {
     "dev": "node scripts/dev.js",
     "build": "node scripts/build.js",
-    "size-runtime": "node scripts/build.js runtime-dom -p -f esm-browser",
-    "size-compiler": "node scripts/build.js compiler-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 global",
     "size": "yarn size-runtime && yarn size-compiler",
     "lint": "prettier --write --parser typescript 'packages/**/*.ts'",
     "test": "jest"
index 6741396ace9a880836404607e79105ca092a4d9e..c7e0779a8d5af8ca7fb6be15d8d287ebd3673b22 100644 (file)
@@ -2,6 +2,7 @@
 declare var __DEV__: boolean
 declare var __JSDOM__: boolean
 declare var __BROWSER__: boolean
+declare var __RUNTIME_COMPILE__: boolean
 declare var __COMMIT__: string
 
 // Feature flags
index 08cc7cbee76d31c8d9361c4e07eb2e0ee6c6d8b6..d9e1e9b9652bfa95b0d14eca5df40910d5c5e53f 100644 (file)
@@ -320,7 +320,7 @@ function finishComponentSetup(
 ) {
   const Component = instance.type as ComponentOptions
   if (!instance.render) {
-    if (Component.template && !Component.render) {
+    if (__RUNTIME_COMPILE__ && Component.template && !Component.render) {
       if (compile) {
         Component.render = compile(Component.template, {
           onError(err: CompilerError) {
index 332b645d60995b8c1836247f9e01f5e5099e1507..02a2ca2d841b5e67abdb45fc859c5b9a48c406ee 100644 (file)
@@ -48,7 +48,7 @@ const publicPropertiesMap = {
   $options: 'type'
 }
 
-export const PublicInstanceProxyHandlers = {
+export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
   get(target: ComponentInternalInstance, key: string) {
     const { renderContext, data, props, propsProxy } = target
     if (data !== EMPTY_OBJ && hasOwn(data, key)) {
@@ -76,11 +76,7 @@ export const PublicInstanceProxyHandlers = {
     }
     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 {
     const { data, renderContext } = target
     if (data !== EMPTY_OBJ && hasOwn(data, key)) {
@@ -105,3 +101,11 @@ export const PublicInstanceProxyHandlers = {
     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)
+  }
+}
index d71ef483fe564be690e488a090b52278d709886d..9eeca408d5659492f62c7969cf4b8917d002a9d8 100644 (file)
@@ -76,6 +76,7 @@ function createConfig(output, plugins = []) {
   const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
   const isBundlerESMBuild = /\.esm\.js$/.test(output.file)
   const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file)
+  const isRuntimeCompileBuild = /^dist\/vue\./.test(output.file)
 
   if (isGlobalBuild) {
     output.name = packageOptions.name
@@ -120,7 +121,8 @@ function createConfig(output, plugins = []) {
         isProductionBuild,
         isBundlerESMBuild,
         (isGlobalBuild || isBrowserESMBuild) &&
-          !packageOptions.enableNonBrowserBranches
+          !packageOptions.enableNonBrowserBranches,
+        isRuntimeCompileBuild
       ),
       ...plugins
     ],
@@ -133,7 +135,12 @@ function createConfig(output, plugins = []) {
   }
 }
 
-function createReplacePlugin(isProduction, isBundlerESMBuild, isBrowserBuild) {
+function createReplacePlugin(
+  isProduction,
+  isBundlerESMBuild,
+  isBrowserBuild,
+  isRuntimeCompileBuild
+) {
   return replace({
     __COMMIT__: `"${process.env.COMMIT}"`,
     __DEV__: isBundlerESMBuild
@@ -143,9 +150,11 @@ function createReplacePlugin(isProduction, isBundlerESMBuild, isBrowserBuild) {
         !isProduction,
     // If the build is expected to run directly in the browser (global / esm-browser builds)
     __BROWSER__: isBrowserBuild,
+    // support compile in browser?
+    __RUNTIME_COMPILE__: isRuntimeCompileBuild,
     // support options?
     // 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,
     // this is only used during tests
     __JSDOM__: false
index 2e576d7a39551fef8313238f839b0dcbebecd4c5..fbf1c9388404136681aaf2cea40e3be9124f6c30 100644 (file)
@@ -28,8 +28,12 @@ const formats = args.formats || args.f
 const devOnly = args.devOnly || args.d
 const prodOnly = !devOnly && (args.prodOnly || args.p)
 const buildAllMatching = args.all || args.a
+const lean = args.lean || args.l
 const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
-;(async () => {
+
+run()
+
+async function run() {
   if (!targets.length) {
     await buildAll(allTargets)
     checkAllSizes(allTargets)
@@ -37,7 +41,7 @@ const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
     await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
     checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
   }
-})()
+}
 
 async function buildAll(targets) {
   for (const target of targets) {
@@ -54,7 +58,6 @@ async function build(target) {
   const env =
     (pkg.buildOptions && pkg.buildOptions.env) ||
     (devOnly ? 'development' : 'production')
-
   await execa(
     'rollup',
     [
@@ -66,7 +69,8 @@ async function build(target) {
         `TARGET:${target}`,
         formats ? `FORMATS:${formats}` : ``,
         args.types ? `TYPES:true` : ``,
-        prodOnly ? `PROD_ONLY:true` : ``
+        prodOnly ? `PROD_ONLY:true` : ``,
+        lean ? `LEAN:true` : ``
       ]
         .filter(Boolean)
         .join(',')
@@ -118,7 +122,7 @@ function checkAllSizes(targets) {
 
 function checkSize(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)) {
     const file = fs.readFileSync(esmProdBuild)
     const minSize = (file.length / 1024).toFixed(2) + 'kb'