Bundle size analysis helps you see how big your Angular app files are. Smaller bundles load faster and make users happy.
Bundle size analysis in Angular
ng build --stats-json
# Then use a tool like 'source-map-explorer' to analyze
npx source-map-explorer dist/project-name/main.*.jsRun ng build --stats-json to create a stats file for analysis.
Use tools like source-map-explorer or webpack-bundle-analyzer to visualize bundle contents.
stats.json file in the dist/project-name folder.ng build --stats-json
npx source-map-explorer dist/my-app/main.*.js
npm install -g webpack-bundle-analyzer webpack-bundle-analyzer dist/my-app/stats.json
This example shows the commands you run in your terminal to generate and view the bundle size report.
You do not write code inside Angular files for this; it is a build and analysis step.
/* Steps to analyze bundle size in Angular */ // 1. Build the app with stats // Run in terminal: // ng build --stats-json // 2. Analyze with source-map-explorer // Run in terminal: // npx source-map-explorer dist/my-app/main.*.js // This opens a browser window showing bundle size breakdown.
Always analyze bundle size after adding new libraries to catch big increases early.
Lazy loading modules in Angular can reduce initial bundle size and improve load speed.
Use ng build --prod for production builds to get accurate bundle sizes with optimizations.
Bundle size analysis helps find what makes your Angular app big.
Use ng build --stats-json and tools like source-map-explorer to see details.
Smaller bundles mean faster loading and better user experience.