RFC: Unify apps and ESM views #1531
Unanswered
cristiano-belloni
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a discussion about the differences and similarities between the upcoming ESM views and regular modular apps. ESM views are a breaking change which shifts the concept of "modular view" from "plain package with a React dependency" to "ESM micro-frontend that deduplicate dependencies via an external CDN". The question is if we can see views as just another type of app (or vice-versa), in light of the fact that apps and ESM views share almost the same build configuration - and if it makes sense, at this point, to merge the two modular types into one.
Differences
index.html
must be provided by developer and apublic
directory can be provided + will be linked in index if needed (like CRA)index.html
can't be specified. A syntheticindex.html
is generated for iframe compatibilityindex.html
style
field of the output package manifest, for an host to load it. Imported external CSS can be rewritten to be loaded from CDN and possibly sandboxed or deduplicated (see CSS module scripts and constructable stylesheets).Unify apps and ESM views
This RFC exists to see if it is feasible to unify upcoming ESM views and apps into a single modular
type
(exact type is TBD). Modular could decide to build an app as an ESM module if a particular environment variable is defined to a particular value (ieMODULAR_ESM_BUILD="true"
) or to a "regular", fully-bundled app otherwise. The biggest problem would be that existing apps can't be interchangeably built as ESM views and viceversa: while regular apps expose an entrypoint that renders a React component onto a DOM element, ESM views just expose a React component that can be imported at runtime and rendered as part of an existing React tree. This means that, as it stands now, it's not possible to build a regular app as an ESM view and viceversa: they're structurally different, unless the user somehow can select the entrypoint to build or we decide a fixed filename schema to differentiate between entry points. In more detail:module
field of its dependency manifest, while a regular application won't have that. An external host application can look at the dependency manifest and decide whether to load an app as an ESM module or as an iframe by looking at themodule
field in dependency manifest (if empty -> must load as an iframe. If present, can import dynamically and add it to the react tree). We can also decide that all apps only export a React component and that a synthetic index.html + trampoline code is generated to ensure that regular and esm apps can be built from the same code, but that would change how regular apps are built and will need code changes from users (remove index.js, remove index.html). Other avenues to interchangeability are: letting the user specify which entrypoint to build or have a fixed filename schema (egindex.js
is always the file that renders a component into a DOM element, whileapp.js
is always the file which exports the root React component)index.html
where provided and generate a synthetic one when not provided. Obviously, regular apps that do things in their custom index (ie loading fonts) won't be interchangeable with ESM apps loaded dynamically.style
field in the output package manifest for an host application to import it at runtime, similar to what it does for the js entrypoint. We don't need any special measure because CSS is always bundled separately.Beta Was this translation helpful? Give feedback.
All reactions