We covered build budgets and how they can help keep your application performant by detecting when a new dependency dramatically increases the size of your build output.
If you want to look at your build bundle and determine which dependency/module is the biggest, there’s another tool at your disposal: The Webpack Bundle Analyzer.
To install it, use the following npm
command:
npm install --save-dev webpack-bundle-analyzer
Then, run your Angular build with the option that generates build statistics:
ng build --stats-json
Finally, run the Webpack Bundle Analyzer to read those build stats and give you a visual output of that bundle:
npx webpack-bundle-analyzer dist/stats.json
This command opens a new tab in your browser with the following user interface. Each rectangle represents a Javascript module. The bigger the rectangle, the bigger the module.
In the above example, we can see that the application code (main.js
– in green color) is a lot smaller than the application dependencies.
For instance, we could improve this project by removing polyfills.js
, as these polyfills were included to maintain compatibility with the now-retired Internet Explorer, and they take more space than our application code!