diff --git a/package.json b/package.json index f8d3bcb9..3f4a7461 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/support/bundle-size.js b/support/bundle-size.js new file mode 100644 index 00000000..2e249de6 --- /dev/null +++ b/support/bundle-size.js @@ -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();