RFC: Build-level support for dynamic loading of views / apps #1311
-
Right now, Modular can generate full-featured applications, which:
and views , which:
In the interest of supporting microfrontends and dynamic loading, it would be useful to specify a mechanism which uses one of the previous concepts (or both) to generate a distributable build that can be imported dynamically by a third party platform / client, without knowing of their existence at build time. Currently, I see two main options:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Thanks for writing this. I'd like to understand more clearly why option 1 requires dependencies to be bundled separately. Thinking out loud, I can imagine two scenarios that would not require this, though each has its drawbacks.
Did you consider these drawbacks unworkable, or are there further complications that I have not thought of? One circumstance that was not called out explicitly in your RFC was that of a view that needs to communicate with the client application and carry out initialisation after it has been imported but before it renders. The view-client interface should be general enough such that a view can export its React components or a custom function for the client to call. In general, I am leaning towards option 1. It seems to me that the "fallback to iframe" functionality you mention is important, and may be a primary use-case for some during local development. This is similar to providing a second entrypoint, except that the entrypoint is essentially built into an index.html template. |
Beta Was this translation helpful? Give feedback.
-
I guess that Modular should strive to be as generic as possible, but maybe it's not hard to provide both behaviours and generate the appropriate
Good point. I feel that the interface between a view and a potential "container" application lies outside of Modular, which only takes care of building packages. But it should be possible to build further functionality on top of what Modular provides. For example, right now views are "expected" to export a |
Beta Was this translation helpful? Give feedback.
-
Summary of what we discussed with @cangarugula and we plan to implement:
|
Beta Was this translation helpful? Give feedback.
-
This was implemented in Modular by adding the |
Beta Was this translation helpful? Give feedback.
This was implemented in Modular by adding the
esm-view
type.