-
Notifications
You must be signed in to change notification settings - Fork 31
/
bundlesize.js
39 lines (34 loc) · 880 Bytes
/
bundlesize.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
const fs = require('fs');
const filesize = require('filesize');
const oldFile = require('./size.json');
const exec = () => {
try {
const stats = fs.statSync('./dist/index.min.js');
const size = stats.size;
fs.unlink('./size.json', () => {
const delta = size - oldFile.new.size || 0;
const sizeObj = {
old: {
...(oldFile.new || {}),
old: undefined,
},
new: {
delta,
prettyDelta: filesize(delta),
size,
prettySize: filesize(size),
},
};
fs.writeFile('./size.json', JSON.stringify(sizeObj), (err) => {
if (err) throw err;
console.log('File is created successfully.');
if (delta > 8000) {
console.log('Delta is bigger than 8k.');
}
});
});
} catch (err) {
console.error(err);
}
};
exec();