Skip to content

Instantly share code, notes, and snippets.

@averyvery
Created May 5, 2016 16:17
Show Gist options
  • Save averyvery/84beb5796964eaad811750607cd78312 to your computer and use it in GitHub Desktop.
Save averyvery/84beb5796964eaad811750607cd78312 to your computer and use it in GitHub Desktop.
require('colors');
import webpack from 'webpack';
import prettysize from 'prettysize';
import fs from 'fs';
import { execSync } from 'child_process';
import Table from 'cli-table';
import config from '../config/build.js';
webpack(config).run((error, stats) => {
if (error) console.log(error.red);
fs.writeFile('./dist/stats.json', JSON.stringify(stats.toJson()));
const assets = stats.compilation.assets;
console.log('\nBUILD SUCCESS!'.green);
console.log(`
${Object.keys(assets).length} assets built
at ${stats.compilation.compiler.outputPath}:\n
`.green);
const table = new Table({
head: [
'Filename',
'Minified Size',
'Gzipped Size',
],
});
Object.keys(assets).map((key) => {
const path = assets[key].existsAt;
const gzippedSize = execSync(`gzip -c ${path} | wc -c`);
return [
key,
prettysize(fs.statSync(path).size),
prettysize(gzippedSize),
];
}).forEach((row) => table.push(row));
console.log(table.toString());
console.log('\n');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment