Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic module import inside Angular 6 library package

I am working on an Angular library with a lot of modules and components, one of them being a plugin loading system.

The way the plugin loading system works is based on the assumption that the project which imports it (via npm) will contain a "plugins" directory with an "index.ts" file in its root and the plugin loading service will import whatever components are exported by index.ts.

I am using the dynamic module importing syntax - the async import('...') statement, which works perfectly when it's pointing to a file which physically exists there, but such a file won't exist at the time when I'm compiling/publishing my library, it exists only at a later stage, inside the project that uses it.

How can I 'trick' the Angular compiler to package the library without the existence of a ../../plugins module and instead fetch the plugins at runtime?

like image 693
Stefan Orzu Avatar asked Mar 14 '26 16:03

Stefan Orzu


1 Answers

You can use a dynamic module loader, like System.JS.

See this question for a similar implementation:

Load new modules dynamically in run-time with Angular CLI & Angular 5

like image 193
kaosdev Avatar answered Mar 17 '26 10:03

kaosdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!