How would you use Angular CLI commands to build your project for production and analyze the resulting bundle size?
Short answer
Running ng build with the production configuration creates an optimized version of your app with smaller file sizes, and tools like the source-map-explorer package let you visualize exactly which parts of your code are taking up the most space in the final bundle, helping you…
Advertisement
AModel answer
Running ng build with the production configuration creates an optimized version of your app with smaller file sizes, and tools like the source-map-explorer package let you visualize exactly which parts of your code are taking up the most space in the final bundle, helping you find opportunities to reduce it.
ng build --configuration production
npx source-map-explorer dist/my-app/*.js
// opens a visual chart showing which packages take up the most spaceReal-world example
A team discovers a large unused charting library was accidentally being included in their main bundle, using source-map-explorer to visualize the bundle after a production build, and removes it to significantly reduce load time.
Likely follow-ups
- What specific optimizations does the production build configuration apply automatically?
- How would you set a bundle size budget that fails the build if exceeded?
Related topics