From 174905aae78555abcbf9e6ea425362f77384ceeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Brugarolas?= Date: Mon, 14 Jan 2019 17:17:58 +0100 Subject: [PATCH] Add bundle analyzer --- package.json | 2 ++ webpack.config.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/package.json b/package.json index cf81344..6e5f27b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "start": "webpack-dev-server --open --config ./webpack.config.js --mode development", "build": "webpack -p --mode production", + "analyzer": "webpack -p --mode production --analyzer", "gh-pages": "webpack -p --mode production --publicPath bruga-weather" }, "keywords": [ @@ -42,6 +43,7 @@ "html-webpack-plugin": "^3.2.0", "html-webpack-include-assets-plugin": "^1.0.6", "remote-file-webpack-plugin": "^1.0.2", + "webpack-bundle-analyzer": "^3.0.3", "webpack": "^4.27.1", "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.1.10" diff --git a/webpack.config.js b/webpack.config.js index 6f8d4ad..1bbb55d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -8,6 +8,8 @@ const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plug module.exports = (env, args) => { const isProduction = args.mode === 'production'; + const isAnalyzer = isProduction && args.analyzer; + const publicPath = isProduction ? '/' + (args.publicPath ? args.publicPath + '/' : '') : '/'; const config = { @@ -126,5 +128,10 @@ module.exports = (env, args) => { babelRules.options.presets.unshift(['minify', { builtIns: true } ]); } + if (isAnalyzer) { + const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; + config.plugins.push(new BundleAnalyzerPlugin()); + } + return config; }