]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: add runtime-global build for vue
authorEvan You <yyx990803@gmail.com>
Mon, 23 Mar 2020 19:09:29 +0000 (15:09 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 23 Mar 2020 19:09:29 +0000 (15:09 -0400)
packages/vue/package.json
rollup.config.js
scripts/build.js

index 271591fe489c9acfca00b6fdcb50a9bf773be96d..4f42e99dde2a8effe748f92a42b3978b2318a2c8 100644 (file)
@@ -18,6 +18,7 @@
       "esm-bundler-runtime",
       "cjs",
       "global",
+      "global-runtime",
       "esm"
     ]
   },
index 8aa1d1980a61e47f583147056dac1d36cd09e6f9..7a35f0cba5949ef071255846cdf0edef2e04032c 100644 (file)
@@ -23,11 +23,6 @@ const outputConfigs = {
     file: resolve(`dist/${name}.esm-bundler.js`),
     format: `es`
   },
-  // main "vue" package only
-  'esm-bundler-runtime': {
-    file: resolve(`dist/${name}.runtime.esm-bundler.js`),
-    format: `es`
-  },
   cjs: {
     file: resolve(`dist/${name}.cjs.js`),
     format: `cjs`
@@ -39,6 +34,15 @@ const outputConfigs = {
   esm: {
     file: resolve(`dist/${name}.esm.js`),
     format: `es`
+  },
+  // main "vue" package only
+  'esm-bundler-runtime': {
+    file: resolve(`dist/${name}.runtime.esm-bundler.js`),
+    format: `es`
+  },
+  'global-runtime': {
+    file: resolve(`dist/${name}.runtime.global.js`),
+    format: 'iife'
   }
 }
 
@@ -54,7 +58,7 @@ if (process.env.NODE_ENV === 'production') {
     if (format === 'cjs' && packageOptions.prod !== false) {
       packageConfigs.push(createProductionConfig(format))
     }
-    if (format === 'global' || format === 'esm') {
+    if (/global/.test(format) || format === 'esm') {
       packageConfigs.push(createMinifiedConfig(format))
     }
   })
@@ -73,7 +77,7 @@ function createConfig(format, output, plugins = []) {
 
   const isProductionBuild =
     process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
-  const isGlobalBuild = format === 'global'
+  const isGlobalBuild = /global/.test(format)
   const isRawESMBuild = format === 'esm'
   const isNodeBuild = format === 'cjs'
   const isBundlerESMBuild = /esm-bundler/.test(format)
@@ -102,8 +106,7 @@ function createConfig(format, output, plugins = []) {
   // during a single build.
   hasTSChecked = true
 
-  const entryFile =
-    format === 'esm-bundler-runtime' ? `src/runtime.ts` : `src/index.ts`
+  const entryFile = /runtime$/.test(format) ? `src/runtime.ts` : `src/index.ts`
 
   const external =
     isGlobalBuild || isRawESMBuild
@@ -210,7 +213,7 @@ function createMinifiedConfig(format) {
   return createConfig(
     format,
     {
-      file: resolve(`dist/${name}.${format}.prod.js`),
+      file: outputConfigs[format].file.replace(/\.js$/, '.prod.js'),
       format: outputConfigs[format].format
     },
     [
index 220512e72ae46e4cbca59c5d2a298b49101b8332..063acd51ff19b17aef4f161022083ec224a6fa77 100644 (file)
@@ -148,18 +148,23 @@ function checkAllSizes(targets) {
 
 function checkSize(target) {
   const pkgDir = path.resolve(`packages/${target}`)
-  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'
-    const gzipped = gzipSync(file)
-    const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
-    const compressed = compress(file)
-    const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
-    console.log(
-      `${chalk.gray(
-        chalk.bold(target)
-      )} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
-    )
+  checkFileSize(`${pkgDir}/dist/${target}.global.prod.js`)
+  checkFileSize(`${pkgDir}/dist/${target}.runtime.global.prod.js`)
+}
+
+function checkFileSize(filePath) {
+  if (!fs.existsSync(filePath)) {
+    return
   }
+  const file = fs.readFileSync(filePath)
+  const minSize = (file.length / 1024).toFixed(2) + 'kb'
+  const gzipped = gzipSync(file)
+  const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
+  const compressed = compress(file)
+  const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
+  console.log(
+    `${chalk.gray(
+      chalk.bold(path.basename(filePath))
+    )} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
+  )
 }