Modern.js
Modern.js is a progressive web development framework based on React. Internally at ByteDance, Modern.js supports the development of thousands of web applications.
The Module Federation team works closely with the Modern.js team and provides the @module-federation/modern-js plugin to help users better utilize Module Federation within Modern.js.
Supports
- modern.js ^2.56.1
- Includes Server-Side Rendering (SSR)
We highly recommend referencing these applications, which showcases the best practices for integrating Modern.js with Module Federation:
Quick Start
Installation
You can install the plugin using the following commands:
Apply Plugin
Apply this plugin in the plugins section of modern.config.ts:
Then, create the module-federation.config.ts file and add the required configuration:
Server-Side Rendering (SSR)
For a better performance experience, Module Federation X Modern.js SSR only supports stream SSR.
There is no difference in using Module Federation in SSR scenarios compared to CSR scenarios; developers can continue with their existing development practices.
Component-Level Data Fetch
See Data Fetching.
The Modern.js plugin re-exports @module-federation/bridge-react from @module-federation/modern-js/react, so you don't need to install it separately.
API
@module-federation/modern-js re-exports @module-federation/modern-js/runtime from the runtime subpath. You can use @module-federation/modern-js/runtime to get the MF Runtime.Runtime。
createRemoteComponent Deprecated
This API has been deprecated. Please use createLazyComponent instead.
Migration Guide
The parameters for createRemoteComponent and createLazyComponent are identical. The only difference is that the createLazyComponent API needs to be called through an instance after registering the plugin.
createRemoteSSRComponent Deprecated
This API has been deprecated. Please use createLazyComponent instead.
Migration Guide
Same as createRemoteComponent#migration-guide
Configuration
ssr
- Type:
false - Required: No
- Default value:
undefined
@module-federation/modern-js will automatically add SSR-related build presets based on server.ssr in the modern.js config.
If the current project only needs to load MF in CSR, you can set ssr: false to help with progressive migration.
fetchServerQuery
- Type:
Record<string, unknown> - Required: No
- Default:
undefined
If a downgrade occurs, an HTTP request will be sent to the server. This configuration can be used to add query parameters to that request.