-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-chart.js
59 lines (40 loc) · 1.38 KB
/
build-chart.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
41
42
43
44
45
46
47
48
49
50
51
const childProcess = require('child_process')
const fs = require('fs')
const component_counts = [1,5,10,20,30,40,50,60,70]
// build the bundles
console.log("building bundles....");
childProcess.execSync('npx rollup -c');
console.log("performing gzips...")
// build the gzips
component_counts.forEach(c =>
childProcess.execSync(`gzip -c public/build/bundle-${c}--lib-min.js > public/build/bundle-${c}--lib-min.js.gz`)
);
function getTotalScriptSize(index) {
const content = fs.readFileSync(index, 'utf-8');
let size = 0;
content.replace(/from '(.*?)'/gmi, (match, fname) => {
const content = fs.readFileSync(fname, 'utf-8');
let non_style_content = content.replace(/<style>.*?<\/style>/mgis, sub => {
return '';
})
size = size + non_style_content.length;
return match;
})
return size;
}
// print the stats
function fileSize(fname) {
return fs.statSync(fname).size
}
console.log('count original lib-nomin nolib-nomin lib-min nolib-min lib-min-gz')
component_counts.forEach(c => {
const bp = `public/build/bundle-${c}-`
console.log([c,
getTotalScriptSize(`index-${c}.js`),
fileSize(`${bp}-lib-nomin.js`),
fileSize(`${bp}-nolib-nomin.js`),
fileSize(`${bp}-lib-min.js`),
fileSize(`${bp}-nolib-min.js`),
fileSize(`${bp}-lib-min.js.gz`)
].join(' '));
})