mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
The previous naming scheme used the name of the resulting bundle file. However, there are cases where multiple bundles have the same filename. This meant whichever bundle finishes last overwrites the previous ones with the same name. The updated naming scheme is `bundle-sizes-<CI_NODE_INDEX>.json`. Instead of generating a separate info file per bundle, it now creates one per process.
26 lines
773 B
JavaScript
26 lines
773 B
JavaScript
'use strict';
|
|
|
|
// Script that combines bundle size information for each build into a single
|
|
// JSON file for easier storage and processing.
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const BUILD_DIR = path.join(__dirname, '../../build');
|
|
|
|
const filenames = fs.readdirSync(path.join(BUILD_DIR, 'sizes'));
|
|
|
|
let bundleSizes = [];
|
|
for (let i = 0; i < filenames.length; i++) {
|
|
const filename = filenames[i];
|
|
if (filename.endsWith('.json')) {
|
|
const json = fs.readFileSync(path.join(BUILD_DIR, 'sizes', filename));
|
|
bundleSizes.push(...JSON.parse(json).bundleSizes);
|
|
}
|
|
}
|
|
|
|
const outputFilename = path.join(BUILD_DIR, 'bundle-sizes.json');
|
|
const outputContents = JSON.stringify({bundleSizes}, null, 2);
|
|
|
|
fs.writeFileSync(outputFilename, outputContents);
|