Skip to content

Commit 691429f

Browse files
committed
chore: add tests for gzip size
1 parent 0a85aab commit 691429f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/test-gzip.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from 'node:fs';
2+
import zlib from 'node:zlib';
3+
4+
const files = ['./dist/index.js', './src/index.d.ts'];
5+
6+
7+
let totalBytes = 0;
8+
9+
files.forEach(file => {
10+
if (fs.existsSync(file)) {
11+
const content = fs.readFileSync(file);
12+
const gzipped = zlib.gzipSync(content);
13+
const bytes = gzipped.length;
14+
const kb = (bytes / 1024).toFixed(2);
15+
16+
totalBytes += bytes;
17+
console.log(`${file}: ${bytes} bytes (${kb} KB)`);
18+
} else {
19+
console.log(`${file}: Not found!`);
20+
}
21+
});
22+
23+
const totalKb = (totalBytes / 1024).toFixed(2);
24+
25+
console.log(`TOTAL BUNDLE SIZE: ${totalBytes} bytes (${totalKb} KB)`);

0 commit comments

Comments
 (0)