-
Notifications
You must be signed in to change notification settings - Fork 2
/
sizecheck.js
40 lines (33 loc) · 879 Bytes
/
sizecheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-env node */
import { promisify } from 'node:util';
import zlib from 'node:zlib';
import { rollup } from 'rollup';
import { swc, defineRollupSwcOption } from 'rollup-plugin-swc3';
async function check() {
let bundle;
let buildFailed = false;
try {
bundle = await rollup({
input: 'src/main.js',
plugins: [swc(defineRollupSwcOption({ minify: true }))],
});
const { output } = await bundle.generate({
format: 'es',
});
for (const chunkOrAsset of output) {
if (chunkOrAsset.type === 'chunk') {
console.log('minified', Buffer.byteLength(chunkOrAsset.code, 'utf8'));
const gz = await promisify(zlib.gzip)(chunkOrAsset.code);
console.log('minzipped', gz.byteLength);
}
}
} catch (error) {
buildFailed = true;
console.error(error);
}
if (bundle) {
await bundle.close();
}
process.exit(buildFailed ? 1 : 0);
}
check();