From 7808d6b75ef4a642d08cacdbbd529b370cd25cba Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Sun, 12 Sep 2021 14:05:13 +0100 Subject: [PATCH] Adds package sizes to build scripts --- packages/intersect/scripts/build.js | 19 +++++++++++++++++-- packages/tldraw/scripts/build.js | 2 -- packages/vec/scripts/build.js | 19 +++++++++++++++++-- tsconfig.json | 8 ++++---- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/intersect/scripts/build.js b/packages/intersect/scripts/build.js index 0ab6f331d..4fbe922f6 100644 --- a/packages/intersect/scripts/build.js +++ b/packages/intersect/scripts/build.js @@ -1,6 +1,7 @@ /* eslint-disable */ const fs = require('fs') const esbuild = require('esbuild') +const { gzip } = require('zlib') const name = process.env.npm_package_name || '' @@ -27,7 +28,7 @@ async function main() { external: ['react', 'react-dom'], }) - esbuild.buildSync({ + const esmResult = esbuild.buildSync({ entryPoints: ['./src/index.ts'], outdir: 'dist/esm', minify: true, @@ -38,9 +39,23 @@ async function main() { jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', external: ['react', 'react-dom'], + metafile: true, }) - console.log(`✔ ${name}: Built package.`) + let esmSize = 0 + Object.values(esmResult.metafile.outputs).forEach((output) => { + esmSize += output.bytes + }) + + fs.readFile('./dist/esm/index.js', (_err, data) => { + gzip(data, (_err, result) => { + console.log( + `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${( + result.length / 1000 + ).toFixed(2)}kb minified)` + ) + }) + }) } catch (e) { console.log(`× ${name}: Build failed due to an error.`) console.log(e) diff --git a/packages/tldraw/scripts/build.js b/packages/tldraw/scripts/build.js index f07c9f56a..6a9124565 100644 --- a/packages/tldraw/scripts/build.js +++ b/packages/tldraw/scripts/build.js @@ -57,8 +57,6 @@ async function main() { ) }) }) - - console.log(`✔ ${name}: Built package.`) } catch (e) { console.log(`× ${name}: Build failed due to an error.`) console.log(e) diff --git a/packages/vec/scripts/build.js b/packages/vec/scripts/build.js index b8677c06b..4f13f24ef 100644 --- a/packages/vec/scripts/build.js +++ b/packages/vec/scripts/build.js @@ -1,6 +1,7 @@ /* eslint-disable */ const fs = require('fs') const esbuild = require('esbuild') +const { gzip } = require('zlib') const name = process.env.npm_package_name || '' @@ -28,7 +29,7 @@ async function main() { external: ['react', 'react-dom'], }) - esbuild.buildSync({ + const esmResult = esbuild.buildSync({ entryPoints: ['./src/index.ts'], outdir: 'dist/esm', minify: true, @@ -40,9 +41,23 @@ async function main() { jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', external: ['react', 'react-dom'], + metafile: true, }) - console.log(`✔ ${name}: Built package.`) + let esmSize = 0 + Object.values(esmResult.metafile.outputs).forEach((output) => { + esmSize += output.bytes + }) + + fs.readFile('./dist/esm/index.js', (_err, data) => { + gzip(data, (_err, result) => { + console.log( + `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${( + result.length / 1000 + ).toFixed(2)}kb minified)` + ) + }) + }) } catch (e) { console.log(`× ${name}: Build failed due to an error.`) console.log(e) diff --git a/tsconfig.json b/tsconfig.json index c702d4527..009ed32d3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,10 +4,10 @@ "exclude": ["node_modules", "**/*.test.ts", "**/*.spec.ts"], "files": [], "references": [ - { "path": "./packages/vec" }, - { "path": "./packages/intersect" }, - { "path": "./packages/tldraw" }, - { "path": "./packages/core" } + { "path": "./packages/vec/src" }, + { "path": "./packages/intersect/src" }, + { "path": "./packages/tldraw/src" }, + { "path": "./packages/core/src" } ], "compilerOptions": { "baseUrl": ".",