Ever had the problem of finding a neat solution to code split & lazy load components in Angular? I did.. so for a couple of projects I’ve used a framework piece which allows easy lazy loading of a component. Since I’ve found it pretty useful (and I haven’t been able to find an existing similar package), I decided to open source it and release an npm package; ngx-loadable-component.
Something Angular handles super well is the ability to code-split and lazy load routes. This is all fine and well when you have route/view centric code you want to chunk, but doesn’t (easily) support the same for individual components. The problem I had was importing shared components (often from external ‘js only’ libraries) and not having them included in any shared bundles.
Simply put, quite possibly. But, as mentioned previously, this package requires no build changes or any other modifications to the ‘standard’ Angular CLI processes. It is quite possible that Angular Elements will be alot easier to combine and code split with Angular 7 (or 8 🤷)… but until then, this package can handle it. Also, if you decide there’s a better way to code split & lazy load, its fairly easy to eject the use of ngx-loadable-component.