Angular 6 - AOT compilation on library to be used as lazily loaded plugin in the main application

605 views Asked by At

I am working on a plugin-based application done in Angular 6. I have 2 projects, a main project and a lib project where i develop the plugins. The plugins get builded with ng build --prod into UMD and then loaded using SystemJs into the main app, where they get compiled using the Compiler class at runtime (the builded plugins are deployed on another server). The main app holds no reference to the lib project at build time.

This is working fine as long as i am running the main app in dev mode. When i try it in prod, it crashes with "Error: Runtime compiler is not loaded" due to the fact that the JIT compiler gets removed in prod build.

My question is: Is it possible to build a Angular 6 Cli Lib project (or not necessarily a cli lib project) ahead of time, load it with SystemJs and then just use the component factories for dynamic component creation? How could i do that build?

I can't build the lib together with the main app as the final goal is having other developers create plugins for the app, and not all components would be used at runtime.

I can't keep the main app without AOT as its gonna grow very large and the performance would have alot to suffer.

I am aware of Angular Elements as well, but i want to have the possibility of creating AOT lib plugins as well.

0

There are 0 answers