Runtime Access
- The features and capabilities of Module Federation
- The glossary of Module Federation
- How to consume and export modules
Currently, Module Federation provides two ways to register and load modules:
-
One is to declare it in the build plugin (usually in the
module-federation.config.tsfile). -
The other way is to directly register and load modules through the
runtimeAPI.
The two modes are not conflicting and can be used together. You can flexibly choose the module registration method and timing according to your actual scenario.
Differences between the two approaches
If the build plugin is used, an MF instance will be automatically created and stored in memory when the project starts. You can directly call methods of the MF instance via the .
If the build plugin is not used, you need to manually create an MF instance before calling the corresponding API.
An object created by the ModuleFederation class that contains all runtime functionality. You can enter __FEDERATION__.__INSTANCES__ in the console to view the full instance information.
Installation
Different project types should install and import Runtime from different entries. Most projects should install @module-federation/enhanced and import Runtime APIs from @module-federation/enhanced/runtime. If your Modern.js project already uses a Module Federation plugin, import Runtime APIs from the plugin's /runtime entry so the framework plugin and manual Runtime calls use the same Runtime instance.
@module-federation/enhanced
Modern.js
For Modern.js v2 projects, install @module-federation/modern-js and import Runtime APIs from @module-federation/modern-js/runtime.
Module Registration
Module Loading
Loading Anonymous Modules
Loading Named Modules
Loading Utility Functions
Read Next
- Runtime API:
createInstance,loadRemote,registerRemotes, and other runtime APIs. - Runtime Plugins: extend the runtime loading flow.
- Runtime Hooks: lifecycle hooks available to runtime plugins.