Skip to content

Commit 472e2cc

Browse files
authored
chore: add english documentation for bridge chapter (#2862)
1 parent 433673e commit 472e2cc

File tree

17 files changed

+558
-176
lines changed

17 files changed

+558
-176
lines changed

.changeset/polite-toys-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/bridge-react-webpack-plugin': patch
3+
---
4+
5+
feat: enchance react-bridge react-router-dom alias according to origin react-router-dom version

apps/router-demo/router-host-2000/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"dependencies": {
1111
"@ant-design/icons": "^5.3.6",
1212
"@module-federation/bridge-react": "workspace:*",
13-
"@module-federation/enhanced": "workspace:*"
13+
"@module-federation/enhanced": "workspace:*",
14+
"react-router-dom": "6.24.1"
1415
},
1516
"devDependencies": {
1617
"@rsbuild/core": "^0.6.15",

apps/router-demo/router-remote1-2001/rsbuild.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
react: path.resolve(__dirname, 'node_modules/react'),
1212
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
1313
// set `react-router-dom/` to reference react-router-dom v5 which shoule be find in node_modules/react-router-dom, otherwise it will cause app.tsx fail to work which in react-router-dom v5 mode.
14-
'react-router-dom/$': path.resolve(
14+
'react-router-dom': path.resolve(
1515
__dirname,
1616
'node_modules/react-router-dom',
1717
),

apps/website-new/docs/en/practice/bridge/index.mdx

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,50 @@
22

33
## Introduction
44

5-
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.
5+
`Bridge` is a utility function provided by `Module Federation` for loading application-level modules.
6+
"Application-level modules" are modules that can run like applications, with framework rendering capabilities and routing abilities.
7+
With `Bridge`, you can render your application in different frameworks and ensure that routing between applications works collaboratively. This is particularly useful for micro-frontend applications.
68

79
:::tip
8-
Before reading this chapter, it's assumed you are already familiar with:
10+
Before reading this chapter, it's assumed you're familiar with:
911

1012
- [How to consume and export modules](../../guide/start/quick-start.mdx)
1113
- [Module Federation Builder plugin](../../guide/basic/rspack.mdx)
12-
- [Features and capabilities of the Module Federation Runtime](../../guide/basic/runtime.mdx)
14+
- [Characteristics and capabilities of Module Federation Runtime](../../guide/basic/runtime.mdx)
1315

1416
:::
1517

1618
## Toolkits
1719

1820
### @module-federation/bridge-react
1921

20-
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](https://github.com/module-federation/core/tree/main/apps/router-demo/router-host-2000) and [Remote demo](https://github.com/module-federation/core/tree/main/apps/router-demo/router-remote2-2002).
22+
`@module-federation/bridge-react` is suitable for React framework types, currently supporting React v16, v17, and v18 versions.
23+
24+
This toolkit provides two APIs:
25+
26+
- createBridgeComponent
27+
28+
> Used to create React application-type module exports. If your application is React-based and you want it to be loaded as an application-type module by another MF application, you should use this to create standard-compliant exports for your application.
29+
30+
- createRemoteComponent
31+
32+
> Used to load application-type modules in a React application. The loaded module must be wrapped by `createBridgeComponent`. `createRemoteComponent` will automatically create a rendering context in your application to ensure the module works properly.
33+
34+
For usage of `@module-federation/bridge-react`, see [Host demo](https://github.com/module-federation/core/tree/main/apps/router-demo/router-host-2000) and [Remote demo](https://github.com/module-federation/core/tree/main/apps/router-demo/router-remote2-2002).
2135

2236
### @module-federation/bridge-vue3
2337

24-
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](https://github.com/module-federation/core/tree/main/apps/router-demo/router-host-2100) and [Remote demo](https://github.com/module-federation/core/tree/main/apps/router-demo/router-remote3-2003).
38+
`@module-federation/bridge-vue3` is suitable for Vue framework types, currently supporting Vue v3 version.
39+
40+
This toolkit provides two APIs:
2541

42+
- createBridgeComponent
43+
44+
> Used to create Vue application-type module exports. If your application is Vue v3-based and you want it to be loaded as an application-type module by another MF application, you should use this to create standard-compliant exports for your application.
45+
46+
- createRemoteComponent
47+
48+
> Used to load application-type modules in a Vue application. The loaded module must be wrapped by `createBridgeComponent`. `createRemoteComponent` will automatically create a rendering context in your application to ensure the module works properly.
2649
2750
## FAQ
2851

@@ -31,17 +54,17 @@ The `@module-federation/bridge-vue3` toolkit is a `bridge` utility function pack
3154
Bridge is mainly used to solve two problems:
3255

3356
* Cross-application framework (React, Vue) loading and rendering
34-
* Support for loading modules with routes (routes can work together properly)
57+
* Support for loading modules with routing (routes can work well together)
3558

36-
These two problems are important features in the "micro-frontend framework".
59+
These two issues are important features in "micro-frontend frameworks"
3760

38-
### How to solve it if the corresponding framework bridge is not provided?
61+
### How to solve if there's no bridge provided for a specific framework?
3962

40-
Currently, `Module Federation` provides official bridge toolkits. If you need bridge toolkits for other frameworks, you can provide feedback via [issue](https://github.com/module-federation/core/issues) or refer to the existing [`Bridge`](https://github.com/module-federation/core/blob/34ba220bcee3d032e4083aae37f802d1ed20d61b/packages/bridge/bridge-react) to implement it yourself.
63+
Currently, `Module Federation` provides official bridge toolkits. If you need bridge toolkits for other frameworks, you can provide feedback through [issues](https://github.com/module-federation/core/issues), or refer to the existing [`Bridge`](https://github.com/module-federation/core/blob/34ba220bcee3d032e4083aae37f802d1ed20d61b/packages/bridge/bridge-react) implementation.
4164

42-
The implementation of `Bridge` is very simple. The core is based on `DOM` rendering. Here is the pseudocode:
65+
The implementation of `Bridge` is very simple, with the core based on `DOM` rendering. Here's some pseudocode:
4366

44-
> Export module
67+
> Exporting module
4568
4669
```tsx
4770
export default function () {
@@ -50,21 +73,24 @@ export default function () {
5073
render(info: { dom: HTMLElement; basename?: string; memoryRoute?: { entryPath: string; } }) {
5174
const root = ReactDOM.createRoot(info.dom);
5275
rootMap.set(info.dom, root);
53-
root.render(<App />);
76+
root.render(
77+
<App />,
78+
);
5479
},
5580
destroy(info: { dom: HTMLElement }) {
5681
const root = rootMap.get(info.dom);
5782
root?.unmount();
5883
},
59-
};
84+
}
6085
}
6186
```
6287

63-
> Load module
88+
> Loading module
6489
6590
```tsx
66-
const LazyComponent = React.lazy(async () => {
91+
const LazyComponent = React.lazy(async () => {
6792
const m = await loadRemote('remote1/export-app');
93+
const providerInfo = m.default;
6894
return {
6995
default: () => {
7096
const rootRef = useRef(null);
@@ -82,15 +108,14 @@ const LazyComponent = React.lazy(async () => {
82108
};
83109
}, []);
84110
return <div ref={rootRef}></div>;
85-
},
111+
}
86112
};
87113
});
88114

89-
function Component() {
90-
return (
91-
<React.Suspense fallback={<div>loading</div>}>
92-
<LazyComponent />
93-
</React.Suspense>
94-
);
115+
function Component () {
116+
return (<React.Suspense fallback={<div>loading</div>}>
117+
<LazyComponent />
118+
</React.Suspense>)
95119
}
96120
```
121+

0 commit comments

Comments
 (0)