galaxyproject / cloudlaunch-ui

A user interface for the cloudlaunch app
MIT License
8 stars 13 forks source link

Split frontend plugins into separate npm installable modules #22

Open nuwang opened 6 years ago

nuwang commented 6 years ago

Currently, all our plugins are contained in a PluginsModule. The PluginsModule is statically referenced by the main app, and the PluginsModule in turn references each plugin through its EntryComponents section. This is because webpack will drop these components during tree shaking if they are not referenced as an EntryComponent. Therefore, although we do use a System.import to "dynamically" import the plugins, these are faux plugins at best and the idea was always to separate them out completely as the Angular ecosystem matured.

We are now probably at a stage where the Angular 5 ecosystem can handle this situation much better. There are good guides [1, 2] on how to package components using rollup and publish them to npm.

However, the best technique for dynamically loading such components is less clear. This is because these packaged components are typically installed from npm, referenced by the main app and the final client js files created through webpack. Instead, we need to directly package the module for consumption by the client using a dynamic module loader, such as the SystemJSNGModuleLoader, as described in this guide here. This means that we should probably be able to compress and package the plugin using webpack or similar, and publish it to a url somewhere, so that it can subsequently be loaded on the client with something like:

System.import('/url/of/webpacked/plugin/module')

Using webpack is probably desirable because we can use hot module replacement etc. to support multiple versions of a plugin.

These are some desirable characteristics: