How can I create a javascript file that contains an Angular 2 module that can be used by other applications, but is loaded at runtime directly from a centralized server and is NOT bundled into a specific application's code?
Think of this as a CDN for an Angular 2 library. The requirement is that the consumers of this library will include a single script on their page.
It is a requirement to implement it this way, so I am not interested in any answers that suggest bundling the library into the individual application's output files. The library script must be loaded directly from the library's server at runtime.
- The centralized web app is called CustomAuth
- CustomAuth has a single Angular 2 module called
CustomAuthModule
- CustomAuthModule exposes several services and components that can be used by external Angular 2 applications.
Here is the desired workflow (from a high level).
- A developer wants to use CustomAuth in their Angular2 application called BookLibrary.
- On the developer's index page, they add a script include that points to
http://server-url/CustomAuth/script
. The consumer should not be required to know anything about module loaders like systemjs or webpack. - In their angular2 code, they import stuff from the CustomAuth module (services, components, etc...).
- When they compile their application using the angular-cli, it will not include the CustomAuth code, but will instead assume that it will be loaded on the fly at runtime.
I've done a lot of research on this, and I'm not having any luck figuring it out. Any help would be greatly appreciated.