File size script
This commit is contained in:
1 parent
57b89445bd
commit
586fef4fb7
1 file changed
+35
@@ -0,0 +1,35 @@
|
|||||||
|
const fs = require("node:fs");
|
||||||
|
const path = require("node:path");
|
||||||
|
const { brotliCompressSync, gzipSync } = require("node:zlib");
|
||||||
|
|
||||||
|
const distDirectory = path.resolve(process.cwd(), "dist");
|
||||||
|
|
||||||
|
function getFiles(directory) {
|
||||||
|
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
||||||
|
const entryPath = path.join(directory, entry.name);
|
||||||
|
return entry.isDirectory() ? getFiles(entryPath) : [entryPath];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toKilobytes(bytes) {
|
||||||
|
return `${(bytes / 1000).toFixed(2)} kB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(distDirectory)) {
|
||||||
|
console.error("dist/ nicht gefunden. Bitte zuerst npm run build ausführen.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = getFiles(distDirectory)
|
||||||
|
.sort()
|
||||||
|
.map((filePath) => {
|
||||||
|
const contents = fs.readFileSync(filePath);
|
||||||
|
return {
|
||||||
|
Datei: path.relative(distDirectory, filePath),
|
||||||
|
Unkomprimiert: toKilobytes(contents.length),
|
||||||
|
GZip: toKilobytes(gzipSync(contents).length),
|
||||||
|
Brotli: toKilobytes(brotliCompressSync(contents).length),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
console.table(rows);
|
||||||
Reference in new issue
Block a user