From 4021307f4c20e5a8c4279e36eee1e905139f6a67 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 1 Oct 2019 16:55:04 -0400 Subject: [PATCH] build: use brotli for checking compressed file sizes --- package.json | 1 + scripts/build.js | 9 ++++++--- yarn.lock | 12 ++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f8c0b617..3fedd2f9 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "devDependencies": { "@microsoft/api-extractor": "^7.3.9", "@types/jest": "^24.0.18", + "brotli": "^1.3.2", "chalk": "^2.4.2", "execa": "^2.0.4", "fs-extra": "^8.1.0", diff --git a/scripts/build.js b/scripts/build.js index 704ebdb0..0ade7371 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -19,6 +19,7 @@ const path = require('path') const zlib = require('zlib') const chalk = require('chalk') const execa = require('execa') +const { compress } = require('brotli') const { targets, fuzzyMatchTarget } = require('./utils') const args = require('minimist')(process.argv.slice(2)) @@ -109,10 +110,12 @@ function checkSize(target) { if (fs.existsSync(esmProdBuild)) { const file = fs.readFileSync(esmProdBuild) const minSize = (file.length / 1024).toFixed(2) + 'kb' - const gzipped = zlib.gzipSync(file) - const gzipSize = (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:${gzipSize}` + `${chalk.gray( + chalk.bold(target) + )} min:${minSize} / brotli:${compressedSize}` ) } } diff --git a/yarn.lock b/yarn.lock index af69dc58..1d1f33af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1618,6 +1618,11 @@ 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.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== + base@^0.11.1: version "0.11.2" resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" @@ -1684,6 +1689,13 @@ braces@^3.0.1: dependencies: fill-range "^7.0.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@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-0.1.2.tgz#425d68a58d3447f02a04aa894187fce8af8b7b8e"