-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a script to compute the bundle size
- Loading branch information
1 parent
f4d898e
commit dd52844
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |