Skip to content

Commit 2b3a9a1

Browse files
committed
feat(webpack): support --analyze
1 parent 9947f33 commit 2b3a9a1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

webpack/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Analyze webpack bundle
2+
3+
npm run analyze

webpack/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"webpack-cli": "^3.0.0",
66
"webpack-dev-server": "^3.0.0",
77
"html-webpack-plugin": "^3.0.0",
8+
"webpack-bundle-analyzer": "^3.0.0",
89
// @if shadow-dom
910
"to-string-loader": "^1.0.0",
1011
// @endif
@@ -34,6 +35,7 @@
3435
"scripts": {
3536
"start": "webpack-dev-server",
3637
"build": "rimraf dist && webpack --env production",
38+
"analyze": "webpack --env production --analyze",
3739
// @if jasmine || tape || mocha
3840
"build:test": "rimraf dist && webpack --env test",
3941
"test:watch": "rimraf dist && webpack --env test --watch --runTest"

webpack/webpack.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
34
// @if jasmine || tape || mocha
45
const WebpackShellPluginNext = require('webpack-shell-plugin-next')
56
// @endif
@@ -37,7 +38,7 @@ const postcssLoader = {
3738
}
3839
};
3940

40-
module.exports = function(env/* @if jasmine || tape || mocha*/, { runTest }/* @endif */) {
41+
module.exports = function(env/* @if jasmine || tape || mocha*/, { runTest, analyze }/* @endif */) {
4142
const production = env === 'production' || process.env.NODE_ENV === 'production';
4243
// @if jasmine || tape || mocha
4344
const test = env === 'test' || process.env.NODE_ENV === 'test';
@@ -134,14 +135,15 @@ module.exports = function(env/* @if jasmine || tape || mocha*/, { runTest }/* @e
134135
},
135136
// @endif
136137
plugins: [
137-
new HtmlWebpackPlugin({ template: 'index.ejs' })/* @if jasmine || tape || mocha*/,
138+
new HtmlWebpackPlugin({ template: 'index.ejs' }),
139+
analyze && new BundleAnalyzerPlugin()/* @if jasmine || tape || mocha*/,
138140
test && runTest && new WebpackShellPluginNext({
139141
dev: false,
140142
swallowError: true,
141143
onBuildEnd: {
142144
scripts: [ 'npm run test:headless' ]
143145
}
144146
})/* @endif */
145-
]/* @if jasmine || tape || mocha*/.filter(p => p)/* @endif */
147+
].filter(p => p)
146148
}
147149
}

0 commit comments

Comments
 (0)