/
githubmirror
/
socket.io
Обзор
Документация
Войти
/
githubmirror
/
socket.io
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/socket.io-client/support/bundle-size.js
35 строк
839 B
Damien Arrachequesne
chore(sio-client): add a script to compute the bundle size
21 сен 2024, 08:34
Не верифицирован
21 сен 2024, 08:34
1a95db2
Код
Авторство
О чём код?
const { resolve } = require("node:path"); const { readFile } = require("node:fs/promises"); const { gzipSync, brotliCompressSync } = require("node:zlib"); const bundles = [ { name: "UMD bundle", path: "dist/socket.io.min.js", }, { name: "ESM bundle", path: "dist/socket.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();