The MF bridge is a utility function provided by Module Federation to help users load application-level modules through Module Federation. It automatically provides the necessary application lifecycle functions render and destroy required by the provider function and ensures compatibility with different framework versions. Additionally, it allows proper routing collaboration between applications.
Before reading this chapter, it's assumed you are already familiar with:
The @module-federation/bridge-react toolkit is a bridge utility function package provided by MF for React v18 applications. The exported createBridgeComponent can be used for exporting modules in React v18 applications. Usage examples of @module-federation/bridge-react can be found in the Host demo and Remote demo.
The @module-federation/bridge-vue3 toolkit is a bridge utility function package provided by MF for Vue v3 applications. The exported createBridgeComponent can be used for exporting modules in Vue v3 sub-applications. Usage examples of @module-federation/bridge-vue3 can be found in the Host demo and Remote demo.
Bridge is mainly used to solve two problems:
These two problems are important features in the "micro-frontend framework".
Currently, Module Federation provides official bridge toolkits. If you need bridge toolkits for other frameworks, you can provide feedback via issue or refer to the existing Bridge to implement it yourself.
The implementation of Bridge is very simple. The core is based on DOM rendering. Here is the pseudocode:
Export module
Load module