Skip to content

Commit dd52844

Browse files
chore: add a script to compute the bundle size
1 parent f4d898e commit dd52844

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"test:node-fetch": "USE_FETCH=1 npm run test:node",
9999
"test:browser": "zuul test/index.js",
100100
"build": "rollup -c support/rollup.config.umd.js && rollup -c support/rollup.config.esm.js",
101+
"bundle-size": "node support/bundle-size.js",
101102
"format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.js' 'test/webtransport.mjs' 'support/**/*.js'",
102103
"format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.js' 'test/webtransport.mjs' 'support/**/*.js'",
103104
"prepack": "npm run compile"

support/bundle-size.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const { resolve } = require("node:path");
2+
const { readFile } = require("node:fs/promises");
3+
const { gzipSync, brotliCompressSync } = require("node:zlib");
4+
5+
const bundles = [
6+
{
7+
name: "UMD bundle",
8+
path: "dist/engine.io.min.js",
9+
},
10+
{
11+
name: "ESM bundle",
12+
path: "dist/engine.io.esm.min.js",
13+
},
14+
];
15+
16+
function format(size) {
17+
return (size / 1024).toFixed(1);
18+
}
19+
20+
async function main() {
21+
for (const bundle of bundles) {
22+
const path = resolve(bundle.path);
23+
const content = await readFile(path);
24+
const gzip = gzipSync(content);
25+
const brotli = brotliCompressSync(content);
26+
27+
console.log(`${bundle.name}`);
28+
console.log(`min: ${format(content.length)} KB`);
29+
console.log(`min+gzip: ${format(gzip.length)} KB`);
30+
console.log(`min+br: ${format(brotli.length)} KB`);
31+
console.log();
32+
}
33+
}
34+
35+
main();

0 commit comments

Comments
 (0)