forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle-size-collect.js
33 lines (25 loc) · 1.02 KB
/
bundle-size-collect.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
// @ts-check
// This script collates bundle size information from minified files in apps/test-bundles/dist
// and writes to apps/test-bundles/dist/bundlesizes.json.
// It is uploaded as an artifact by the build definition in Azure DevOps and used to compare
// baseline and PR file size information which gets reported by Size Auditor.
const fs = require('fs');
const path = require('path');
const distRoot = path.resolve(__dirname, '../apps/test-bundles/dist');
const sizes = {};
const outputFilename = 'bundlesize.json';
var items = fs.readdirSync(distRoot);
items.forEach(item => {
const file = path.join(distRoot, item);
const isMinifiedJavascriptFile = item.match(/.min.js$/);
if (isMinifiedJavascriptFile) {
sizes[getComponentName(item)] = getFilesizeInBytes(file);
}
});
fs.writeFileSync(path.join(distRoot, outputFilename), JSON.stringify({ sizes }));
function getFilesizeInBytes(fileName) {
return fs.statSync(fileName).size;
}
function getComponentName(fileName) {
return path.basename(fileName, '.min.js');
}