In Angular, it is quite easy to break lazy-loading. For example, all it takes is for someone to carelessly import something from a lazy-loaded module into the app module and this module is eagerly loaded. Therefore, I usually check for such errors when reviewing PRs. Currently, I do this manually by looking at the logs of ng build or by inspecting the network logs in the browser DevTools. However, I would like to automate this repetitive task in our CI pipeline.
After trying various methods, I can only think of two more or less suboptimal approaches:
- A script that builds the app and then checks if the expected number of lazy-loaded chunks is in the
distfolder. - E2e tests that assert that a
*.jsfile is loaded when the browser navigates to a specific route.
Is there any better way to programmatically check if lazy-loading works for all lazy-loaded modules?