]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: use custom size check
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 18 Sep 2020 16:53:31 +0000 (18:53 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 2 Oct 2020 12:46:43 +0000 (14:46 +0200)
package.json
rollup.config.js
scripts/check-size.js [new file with mode: 0644]
size-checks/rollup.config.js [new file with mode: 0644]
src/global.d.ts
yarn.lock

index 780358860f07429bf5eb8744a3936842d9d776ad..9977b68e06e5cfb2944b585c5f18291ba3e69270 100644 (file)
@@ -81,6 +81,7 @@
     "@vue/compiler-sfc": "^3.0.0-rc.9",
     "@vue/server-renderer": "^3.0.0-rc.5",
     "axios": "^0.20.0",
+    "brotli": "^1.3.2",
     "browserstack-local": "^1.4.5",
     "chalk": "^4.1.0",
     "chromedriver": "^85.0.0",
index 7a5b1dc6aad3538140426b0ca81faf88c568286a..499c6d353231cb7d50596748a37323470f302a90 100644 (file)
@@ -144,6 +144,9 @@ function createReplacePlugin(
     __TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : false,
     // If the build is expected to run directly in the browser (global / esm builds)
     __BROWSER__: isBrowserBuild,
+    __FEATURE_PROD_DEVTOOLS__: isBundlerESMBuild
+      ? `__VUE_PROD_DEVTOOLS__`
+      : false,
     // is targeting bundlers?
     __BUNDLER__: isBundlerESMBuild,
     __GLOBAL__: isGlobalBuild,
diff --git a/scripts/check-size.js b/scripts/check-size.js
new file mode 100644 (file)
index 0000000..c9e9c14
--- /dev/null
@@ -0,0 +1,24 @@
+const fs = require('fs')
+const path = require('path')
+const chalk = require('chalk')
+const { gzipSync } = require('zlib')
+const { compress } = require('brotli')
+
+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}`
+  )
+}
+
+checkFileSize(path.resolve(__dirname, '../size-checks/dist/webRouter.js'))
diff --git a/size-checks/rollup.config.js b/size-checks/rollup.config.js
new file mode 100644 (file)
index 0000000..73f369d
--- /dev/null
@@ -0,0 +1,58 @@
+import path from 'path'
+import ts from 'rollup-plugin-typescript2'
+import replace from '@rollup/plugin-replace'
+import resolve from '@rollup/plugin-node-resolve'
+import commonjs from '@rollup/plugin-commonjs'
+import { terser } from 'rollup-plugin-terser'
+
+/** @type {import('rollup').RollupOptions} */
+const config = {
+  external: ['vue'],
+  output: {
+    file: path.resolve(__dirname, './dist/webRouter.js'),
+    format: 'es',
+  },
+  input: path.resolve(__dirname, './webRouter.js'),
+  plugins: [
+    replace({
+      __DEV__: false,
+      // this is only used during tests
+      __TEST__: false,
+      // If the build is expected to run directly in the browser (global / esm builds)
+      __BROWSER__: true,
+      // is targeting bundlers?
+      __BUNDLER__: false,
+      __GLOBAL__: false,
+      // is targeting Node (SSR)?
+      __NODE_JS__: false,
+      __VUE_PROD_DEVTOOLS__: false,
+    }),
+    ts({
+      check: false,
+      tsconfig: path.resolve(__dirname, '../tsconfig.json'),
+      cacheRoot: path.resolve(__dirname, '../node_modules/.rts2_cache'),
+      tsconfigOverride: {
+        compilerOptions: {
+          sourceMap: false,
+          declaration: false,
+          declarationMap: false,
+        },
+        exclude: ['__tests__', 'test-dts'],
+      },
+    }),
+    resolve(),
+    commonjs(),
+    terser({
+      format: {
+        comments: false,
+      },
+      module: true,
+      compress: {
+        ecma: 2015,
+        pure_getters: true,
+      },
+    }),
+  ],
+}
+
+export default config
index d1785b3dc697c28858412c0fbe01fc8c6f49c42e..e348e51e212762ba6b95c7cc33753f9e381b7ff8 100644 (file)
@@ -1,4 +1,5 @@
 // Global compile-time constants
 declare var __DEV__: boolean
+declare var __FEATURE_PROD_DEVTOOLS__: boolean
 declare var __BROWSER__: boolean
 declare var __CI__: boolean
index c2fec93fe4c9dee07078436b90bd4fad61e5c4b8..2ef32a9b70347107744ef7961c2e6d858e5d4d82 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -1918,7 +1918,7 @@ balanced-match@^1.0.0:
   resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
   integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
 
-base64-js@^1.0.2:
+base64-js@^1.0.2, base64-js@^1.1.2:
   version "1.3.1"
   resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
   integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
@@ -2066,6 +2066,13 @@ brotli-size@^4.0.0:
   dependencies:
     duplexer "0.1.1"
 
+brotli@^1.3.2:
+  version "1.3.2"
+  resolved "https://registry.yarnpkg.com/brotli/-/brotli-1.3.2.tgz#525a9cad4fcba96475d7d388f6aecb13eed52f46"
+  integrity sha1-UlqcrU/LqWR119OI9q7LE+7VL0Y=
+  dependencies:
+    base64-js "^1.1.2"
+
 browser-process-hrtime@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626"