Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-bundle-analyzer is not working

I run below command to create stats.json:

ng build --prod --stats-json

After this I am executing below code:

webpack-bundle-analyzer dist/stats.json

once I execute it I am receiving below error in my terminal:

'webpack-bundle-analyzer' is not recognized as an internal or external command, operable program or batch file.

I have installed webpack-bundle-analyzer.

In Package.json file it's available

"webpack-bundle-analyzer": "^2.11.1"

Please help me to resolve.

Note : Stats.json is available in dist folder

like image 716
Ambuj Khanna Avatar asked Apr 27 '18 10:04

Ambuj Khanna


Video Answer


2 Answers

If you have npm >5.2 installed, a new utility, npx should already be available
Execute npx webpack-bundle-analyzer dist/stats.json

else you can add a new npm script that calls webpack-bundle-analyzer add this in your package.json

"scripts": {
  "stats": "webpack-bundle-analyzer dist/stats.json",

},

Execute npm run stats

like image 165
Vikas Avatar answered Sep 17 '22 13:09

Vikas


As commands should be added to the PATH before it can be called from terminal/shell. So after I try to install the package into global, I can use it:

npm i -g webpack-bundle-analyzer

I think by adding the directory you install the package locally to the PATH will fix the problem too.

like image 24
Lushang Avatar answered Sep 18 '22 13:09

Lushang