In Angular 9, significant improvements were made to the tree-shaking process, primarily due to the introduction of the Ivy compiler. Tree shaking is a technique used to remove unused code (dead code) from applications during the build process, which results in smaller and more efficient final bundle sizes.
Key Improvements in Tree Shaking with Angular 9 and Ivy Compiler
- Enhanced Static Analysis: Angular 9's Ivy compiler has improved static analysis capabilities. This allows the compiler to more accurately determine which parts of the code are used and which are not. The accuracy in detecting unused code is crucial for effective tree shaking
- Better Dead Code Elimination: With the Ivy compiler, Angular 9 can eliminate more dead code than before. The compiler does this by removing unused parts of Angular itself, not just user-added code. This results in a more streamlined final bundle
- Simplified Configuration: The configuration required to enable tree shaking in Angular 9 has been simplified. This makes it easier for developers to set up and optimize their applications for production builds
- ...