I installed webpack-bundle-analyzer
and need to run it. How can I do it? I have several errors. One of the most common is
Could't analyze webpack bundle
Webpack Bundle Analyzer First up, we have a webpack plugin - webpack-bundle-analyzer. This is a visual tool to see which components are contributing the most to the size of our bundle. It uses the webpack stats JSON file to provide us with an interactive treemap visualization of the contents of our bundle.
Finally I found that one can solve this issue by two ways. See more. In any case you need to add to webpack.config.js
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
and to
plugins : [
new BundleAnalyzerPlugin({
analyzerMode: 'server',
generateStatsFile: true,
statsOptions: { source: false }
}),
...
],
Then if you want to look at the report html page in your browser each time you make a build, no actions are required.
If you want to run the report page from time to time using your CLI, then you need to disable server in the webpack.config.js like this:
plugins : [
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: true,
statsOptions: { source: false }
}),
...
],
and to add the row in the script section of your package.json:
"scripts": {
"bundle-report": "webpack-bundle-analyzer --port 4200 dist/stats.json",
...
}
I made the second choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With