This project demonstrates cases when Angular 19 tree-shakes unused internals of a (3rd party) library and when not - while importing just one component from a library. The cases are:
- ✅ Eagerly loaded component from library (tree shaking works)
- 😕 @Defer-loaded component from library (tree shaking doesn't work)
- ✅ @Defer-loaded local component that wraps a component from library (tree shaking works)
- ✅ @Defer-loaded component from library imported via a local proxy-file instead of directly (tree shaking works)
npm install
# Build all 3 libraries
ng build lib1 && ng build lib2 && ng build lib3 && ng build lib4
# Build app
ng build
# Start http server on a production build
npx http-server dist/test-standalone-minimal/browser
The project contains 3 libraries and a main application. Each library is simple and analogical: it contains a Component A, Component B and Service, e.g.: lib1
contains Lib1AComponent
, Lib1BComponent
and Lib1Service
.
- Eagerly loaded Component A from lib1
- Defer-loaded Component A from lib2
- Defer-loaded Local Component that wraps Component A from lib3
- Defer-loaded Component A from lib4 imported via a local proxy-file (instead of directly)