manfredsteyer / ngx-build-plus

Extend the Angular CLI's default build behavior without ejecting, e. g. for Angular Elements
1.19k stars 136 forks source link

Drawback w/ externalizing Angular libraries #248

Open yangwen2 opened 3 years ago

yangwen2 commented 3 years ago

Author's blog post promotes a strategy of externalizing angular libraries so that each individual Angular Elements bundle can be as small as possible (via exclusion of necessary Angular libraries). https://www.angulararchitects.io/aktuelles/your-options-for-building-angular-elements/

My observation from practicing this approach is when we externalize any of the Angular libraries, we also need to externalize @angular/compiler. Otherwise, we'll get runtime errors of undefined window.ng. There appears to be some references that are broken when @angular/compiler is not externalized to the global scope.

The need to externalize the compiler represents a major drawback of this strategy, since AOT build eliminates the need for the compiler at runtime. The UMD bundle for this is library is of non-trivial size.

Has anyone dealt with this concern?

ravitejrai commented 3 years ago

@yangwen2 I am facing the same issue getting runtime errors of undefined window.ng. How are you externalizing angular compiler ?

yangwen2 commented 3 years ago

We are currently externalizing the entire angular compiler umd bundle.

Seems like a half-baked pattern - To externalize some set of the ng library, at the cost of needing to externalize the compiler, which directly impacts time to the LCP.

haskelcurry commented 1 year ago

Any comments on this, please, @manfredsteyer ?