Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run webpack-bundle-analyzer?

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
like image 998
Roman Avatar asked May 09 '18 18:05

Roman


People also ask

How do I check my webpack bundle size?

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.


1 Answers

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.

like image 162
Roman Avatar answered Sep 24 '22 10:09

Roman