Skip to content

Commit

Permalink
Add bundle analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Brugarolas committed Jan 14, 2019
1 parent c7af011 commit 174905a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}

0 comments on commit 174905a

Please sign in to comment.