Skip to content

Commit

Permalink
chore: add a script to compute the bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed May 31, 2024
1 parent f4d898e commit dd52844
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"test:node-fetch": "USE_FETCH=1 npm run test:node",
"test:browser": "zuul test/index.js",
"build": "rollup -c support/rollup.config.umd.js && rollup -c support/rollup.config.esm.js",
"bundle-size": "node support/bundle-size.js",
"format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.js' 'test/webtransport.mjs' 'support/**/*.js'",
"format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.js' 'test/webtransport.mjs' 'support/**/*.js'",
"prepack": "npm run compile"
Expand Down
35 changes: 35 additions & 0 deletions support/bundle-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { resolve } = require("node:path");
const { readFile } = require("node:fs/promises");
const { gzipSync, brotliCompressSync } = require("node:zlib");

const bundles = [
{
name: "UMD bundle",
path: "dist/engine.io.min.js",
},
{
name: "ESM bundle",
path: "dist/engine.io.esm.min.js",
},
];

function format(size) {
return (size / 1024).toFixed(1);
}

async function main() {
for (const bundle of bundles) {
const path = resolve(bundle.path);
const content = await readFile(path);
const gzip = gzipSync(content);
const brotli = brotliCompressSync(content);

console.log(`${bundle.name}`);
console.log(`min: ${format(content.length)} KB`);
console.log(`min+gzip: ${format(gzip.length)} KB`);
console.log(`min+br: ${format(brotli.length)} KB`);
console.log();
}
}

main();

0 comments on commit dd52844

Please sign in to comment.