How to analyze your Angular build output?

How to analyze your Angular build output?

Analyze Angular bundle size with ng build --stats-json and a visualization tool to identify oversized dependencies, unnecessary imports, and source code worth simplifying or refactoring.

AC

Alain Chautard

December 4, 2026

When we build an Angular application, the browser must download, parse, and interpret its JavaScript before rendering any component on the screen. This means that the smaller our code output, the faster the application loads.

How to optimize our build size? First, we can use lazy loading, which should be used by most Angular applications no matter what.

Second, we can look at what's inside our code output. Unwanted libraries can get imported and included by accident in your build. This article explains how to identify such libraries.

How to analyze our code output?

Here is how to get a bundle analysis:

  • Run ng build --stats-json in your project. This generates a stats file: dist/your-project/stats.json
  • Open the esbuild Bundle Size Analyzer website and drop that stats.json into it. You get a treemap showing how much each dependency weighs in the initial bundle and in the lazy chunks. Everything stays local in the browser.

An alternative is to run the tool as a command-line option: npx source-map-explorer dist/your-project/browser/*.js, after a build with sourceMap: true.

In the browser, you would see your build output mapped as follows:

You'll notice that most of that code comes from node_modules, which means it comes from the Angular framework or other dependencies. In the above picture, we can see a forms/signals.mjs being included. What if I'm not using Signal Forms at all? This means I might be importing Signal Forms features that aren't really needed.

Always remember that an ES import from node_modules means: "I need this code in my application". As a result, cleaning up unused imports is very important.

The map on the website is clickable. Here I clicked on the /src section to see how much of my source code makes up that build, and which components are the biggest:

The bigger the rectangle, the more time we should spend looking at that source code to see if it could be simplified or refactored.


Originally published by Alain Chautard on the Angular Training blog.

Ready to prove your Angular skills?

Get certified in Angular

More Angular articles

Keep learning Angular. Then get certified when you are ready.