@bundle-analyzer/webpack-plugin
Version:
Bundle Analyzer webpack plugin.
40 lines (35 loc) • 990 B
JavaScript
;
var _core = require("@bundle-analyzer/core");
class BundleAnalyzer {
constructor({
token,
configFile
} = {}) {
this.token = token;
this.configFile = configFile;
}
apply(compiler) {
const isProductionLikeMode = compiler.options.mode === 'production' || !compiler.options.mode;
if (!isProductionLikeMode) return;
const {
token,
configFile
} = this;
compiler.hooks.afterEmit.tapAsync('@bundle-analyzer/webpack-plugin', (hookCompiler, callback) => {
const stats = hookCompiler.getStats().toJson({
maxModules: Infinity,
source: false
});
(0, _core.uploadStats)({
webpackStats: stats,
token,
configFile,
fileSystem: compiler.outputFileSystem
}).then(() => callback()).catch(error => {
callback(new Error(`Bundle Analyzer - ${error.message}`));
});
});
}
}
module.exports = BundleAnalyzer;
module.exports.default = BundleAnalyzer;