element-portable/scripts/benchmark-bundle.ts
Michael Telatynski 90342f1b82
Initial work towards benchmarking bundle size over time
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
2024-11-26 17:21:24 +00:00

28 lines
696 B
TypeScript
Executable file

#!/usr/bin/env -S yarn --silent tsx
import { glob } from "glob";
import path from "node:path";
import { stat } from "node:fs/promises";
async function main() {
const cwd = path.join(__dirname, "..", "webapp");
const jsfiles = await glob("**/*.js", { cwd });
const sizes = await Promise.all(
jsfiles.map(async (file) => {
const data = await stat(path.join(cwd, file));
return data.size;
}),
);
const totalBytes = sizes.reduce((acc, size) => acc + size, 0);
console.log([
{
name: "Total JS bundle size",
unit: "Megabytes",
value: totalBytes / 1024 / 1024,
},
]);
}
main();