Reputation: 688
Im starting to develop a front end for a completely modular backend (a vertx verticles docker cluster).
The main idea/problem is to have a base ng2 application that defines a dashboard, sidemenu, other base components, and connects to the backend discovering which modules are enabled, via some kind of list of manifests containing the the path for the required JS files/bundles, the modules should be completely independent, something that you would be able to download from github and place in a folder.
So far the closest thing I've found was this question, Angular2: Loading modules dynamically from a given folder, that show how to load modules in runtime, but I hanven't found a way to develop and build the bundles independently.
Is this even possible? Can you guys point me in the right direction? Have I missed any example of this?
Upvotes: 5
Views: 181
Reputation: 2186
It's kind of a tricky question but from my understanding the closest you could get to that would be to actually distribute your modules as standalone modules in github/npm and then add them as dependencies in your project.
You could then set up lazy-loaded routes which would import these standalone modules. You would still have to explicitly reference them everywhere so its not a pure discover from a directory kinda deal, not sure how much of a requirement that is.
In general, however, it's worth noting that the lazy loading might not be ideal if you're bringing in providers. You usually want to import those using forRoot() in your main module and avoid providing them in modules that might be included more than once lest you get multiple instances.
Upvotes: 0
Reputation: 36594
If you are going for Angular CLI for this instead of rolling your own build, all the routes have to be defined up-front.
What you can do though is set all modules are lazy loaded router modules (using load-children
, and then have router guards for loading them depending on what dashboard says for example.
Upvotes: 1