12

I'm trying to generate the stats.json file for my Angular 6 application. Below things I've already tried, but the file is not getting generated at all. My system requires to have "npm run" before every angular cli command.

  1. I've ran "npm run ng build --prod --stats-json" as well as "npm run ng build --prod --stats-json=true".

  2. I've ran "npm run ng build --stats-json" as well as "npm run ng build --stats-json=true" (without the build command).

  3. Used "npm run ng build --statsJson=true" by taking reference from cli documentation.

But still stats.json file is not being generated, which I want to read using webpack bundle analyzer. Any help, suggestion or correction in this regard is welcome.

Below are the scripts in my package.json.

"scripts": {

"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"gulp": "gulp",
"bundle-report": "webpack-bundle-analyzer dist/stats.json",
"stats": "webpack-bundle-analyzer dist/stats.json"

},

5 Answers 5

21

I found mine was in /dist.

This means if you look to git for changes appearing, it might be ignored.

Sign up to request clarification or add additional context in comments.

1 Comment

ah this, ty. Underrated answer
5

Check your package.json there should be a script section like below,

 "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

if it's then run

npm run build -- --statsJson=true

if your script is different please post the script section from your packageJSon will update answer based on that

8 Comments

I've added the scripts above, please suggest.
The above command worked and I finally got the file. Thanks Ravin
For production build run this. npm run build -- --prod --statsJson=true
why no hyphen in stats-json as shown in the command ng build --stats-json. this used to work for me but isn't now with Angular 9
Hi @Simon_Weaver, I've found that the output json file name has been renamed to stats-es2015.json with Angular 9
|
3

I don't know if the argument --statsJson=true is not available in newer versions of the CLI or if it's because I'm using NX to build my app but anywway, here's how you can make it work:

  • Open angular.json file
  • In the JSON structure go to projects / [YOUR-APP] / architect / build / configurations / production
  • Add a new key in this JSON object: "statsJson": true

Launch your build and don't forget to launch it with the correct environment. In this case production so I need to pass the --prod argument when building the app otherwise it'll pick another configuration which doesn't have the new flag "statsJson": true!

Comments

2

When I ran this command:

npm run build --stats-json,

It generated one file called:

stats-es2015.json

Then, everything was ok, when I ran:

npm run webpack-bundle-analyzer dist/PROJECT_NAME/stats-es2015.json

My environment was:

"@angular/core": "~9.0.6",
"webpack-bundle-analyzer": "^4.4.2"

Comments

-1

Please check out my simple workaround that can be used to create manifest and read its content by i.e. Node.js app.

https://www.npmjs.com/package/ng-manifest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.