Initial work towards benchmarking bundle size over time

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2024-11-26 17:21:24 +00:00
parent de820e11fc
commit 90342f1b82
7 changed files with 269 additions and 102 deletions

28
scripts/benchmark-bundle.ts Executable file
View File

@@ -0,0 +1,28 @@
#!/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();

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S npx ts-node
#!/usr/bin/env -S yarn --silent tsx
import fs from "node:fs";
import path from "node:path";