UNPKG

webpack-bundle-analysis-cli

Version:

A webpack plugin analyzer in command line. Can be used for webpack health checks.

41 lines (35 loc) 1.08 kB
const babar = require('babar'); const fs = require('fs'); const path = require('path'); module.exports = class PostBuildPlugin { constructor(options) { this.options = options || { height: 10, width: 40, color: 'cyan' }; this.postBuildProcess = this.postBuildProcess.bind(this); } postBuildProcess(stats) { const filePath = stats.compilation.options.output.path; const { height, width, color } = this.options; const data = []; let i = 0; fs.readdir(filePath, (error, files) => { if (error) throw error; files.forEach(file => { const { size } = fs.statSync(path.resolve(filePath, file)); data.push([++i, size]); }) console.log(babar(data, { color, width, height, yFractions: 1 })); }); } apply(compiler) { compiler.hooks.done.tap("PostBuildPlugin", this.postBuildProcess); } };