@module-federation/bridge-react-webpack-plugin 0.0.0-docs-remove-invalid-lark-link-20251205062649

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # React Bridge
2
+
3
+ React bridge is used to load the routing module in mf, so that the routing module can work properly with the host environment.
4
+
5
+ > When to use
6
+
7
+ - Load the route module
8
+ - Load across the front end framework
9
+
10
+ ## How to use
11
+
12
+ # 1. Install the react bridge library
13
+
14
+ ```bash
15
+ pnpm add @module-federation/bridge-react
16
+ ```
17
+
18
+ # 2. Configure the react bridge library
19
+
20
+ > Use createBridgeComponent create component provider
21
+
22
+ ```jsx
23
+ // ./src/index.tsx
24
+ import { createBridgeComponent } from '@module-federation/bridge-react';
25
+
26
+ function App() {
27
+ return ( <BrowserRouter basename="/">
28
+ <Routes>
29
+ <Route path="/" Component={()=> <div>Home page</div>}>
30
+ <Route path="/detail" Component={()=> <div>Detail page</div>}>
31
+ </Routes>
32
+ </BrowserRouter>)
33
+ }
34
+
35
+ export default createBridgeComponent({
36
+ rootComponent: App
37
+ });
38
+ ```
39
+
40
+ > set alias to proxy
41
+
42
+ ```js
43
+ //rsbuild.config.ts
44
+ export default defineConfig({
45
+ source: {
46
+ alias: {
47
+ 'react-router-dom$': path.resolve(
48
+ __dirname,
49
+ 'node_modules/@module-federation/bridge-react/dist/router.es.js',
50
+ ),
51
+ },
52
+ },
53
+ server: {
54
+ port: 2001,
55
+ host: 'localhost',
56
+ },
57
+ dev: {
58
+ assetPrefix: 'http://localhost:2001',
59
+ },
60
+ tools: {
61
+ rspack: (config, { appendPlugins }) => {
62
+ delete config.optimization?.splitChunks;
63
+ config.output!.uniqueName = 'remote1';
64
+ appendPlugins([
65
+ new ModuleFederationPlugin({
66
+ name: 'remote1',
67
+ exposes: {
68
+ './export-app': './src/index.tsx',
69
+ }
70
+ }),
71
+ ]);
72
+ },
73
+ },
74
+ });
75
+ ```
76
+
77
+ # 3. Load the module with routing
78
+
79
+ ```js
80
+ //rsbuild.config.ts
81
+ export default defineConfig({
82
+ tools: {
83
+ rspack: (config, { appendPlugins }) => {
84
+ config.output!.uniqueName = 'host';
85
+ appendPlugins([
86
+ new ModuleFederationPlugin({
87
+ name: 'host',
88
+ remotes: {
89
+ remote1: 'remote1@http://localhost:2001/mf-manifest.json',
90
+ },
91
+ }),
92
+ ]);
93
+ },
94
+ },
95
+ });
96
+ ```
97
+
98
+ > Use the module
99
+
100
+ ```jsx
101
+ // ./src/index.tsx
102
+ import { createBridgeComponent } from '@module-federation/bridge-react';
103
+
104
+ const Remote1 = createBridgeComponent(()=> import('remote1/export-app'));
105
+
106
+ function App() {
107
+ return ( <BrowserRouter basename="/">
108
+ <ul>
109
+ <li>
110
+ <Link to="/">
111
+ Home
112
+ </Link>
113
+ </li>
114
+ <li>
115
+ <Link to="/remote1">
116
+ Remote1
117
+ </Link>
118
+ </li>
119
+ </ul>
120
+ <Routes>
121
+ <Route path="/" Component={()=> <div>Home page</div>}>
122
+ <Route path="/remote1" Component={()=> <Remote1 />}>
123
+ </Routes>
124
+ </BrowserRouter>)
125
+ }
126
+
127
+ const root = ReactDOM.createRoot(document.getElementById('root')!);
128
+ root.render(
129
+ <App />
130
+ );
131
+ ```
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "react-router-dom",
3
+ "version": "5.3.4",
4
+ "description": "DOM bindings for React Router",
5
+ "homepage": "https://reactrouter.com/",
6
+ "repository": {
7
+ "url": "https://github.com/remix-run/react-router.git",
8
+ "type": "git",
9
+ "directory": "packages/react-router-dom"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Remix Software <hello@remix.run>",
13
+ "files": [
14
+ "LICENSE",
15
+ "README.md",
16
+ "BrowserRouter.js",
17
+ "HashRouter.js",
18
+ "Link.js",
19
+ "MemoryRouter.js",
20
+ "NavLink.js",
21
+ "Prompt.js",
22
+ "Redirect.js",
23
+ "Route.js",
24
+ "Router.js",
25
+ "StaticRouter.js",
26
+ "Switch.js",
27
+ "cjs",
28
+ "es",
29
+ "esm",
30
+ "index.js",
31
+ "generatePath.js",
32
+ "matchPath.js",
33
+ "modules/*.js",
34
+ "modules/utils/*.js",
35
+ "withRouter.js",
36
+ "warnAboutDeprecatedCJSRequire.js",
37
+ "umd"
38
+ ],
39
+ "main": "index.js",
40
+ "module": "esm/react-router-dom.js",
41
+ "sideEffects": false,
42
+ "scripts": {
43
+ "build": "rollup -c",
44
+ "lint": "eslint modules"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=15"
48
+ },
49
+ "dependencies": {
50
+ "@babel/runtime": "^7.12.13",
51
+ "history": "^4.9.0",
52
+ "loose-envify": "^1.3.1",
53
+ "prop-types": "^15.6.2",
54
+ "react-router": "5.3.4",
55
+ "tiny-invariant": "^1.0.2",
56
+ "tiny-warning": "^1.0.0"
57
+ },
58
+ "browserify": {
59
+ "transform": [
60
+ "loose-envify"
61
+ ]
62
+ },
63
+ "keywords": [
64
+ "react",
65
+ "router",
66
+ "route",
67
+ "routing",
68
+ "history",
69
+ "link"
70
+ ]
71
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "react-router-dom",
3
+ "version": "6.22.3",
4
+ "description": "Declarative routing for React web applications",
5
+ "keywords": [
6
+ "react",
7
+ "router",
8
+ "route",
9
+ "routing",
10
+ "history",
11
+ "link"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/remix-run/react-router",
16
+ "directory": "packages/react-router-dom"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Remix Software <hello@remix.run>",
20
+ "sideEffects": false,
21
+ "main": "./dist/main.js",
22
+ "unpkg": "./dist/umd/react-router-dom.production.min.js",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "dependencies": {
26
+ "@remix-run/router": "1.15.3",
27
+ "react-router": "6.22.3"
28
+ },
29
+ "devDependencies": {
30
+ "react": "^18.3.1",
31
+ "react-dom": "^18.3.1"
32
+ },
33
+ "peerDependencies": {
34
+ "react": ">=16.8",
35
+ "react-dom": ">=16.8"
36
+ },
37
+ "files": [
38
+ "dist/",
39
+ "CHANGELOG.md",
40
+ "LICENSE.md",
41
+ "README.md",
42
+ "server.d.ts",
43
+ "server.js",
44
+ "server.mjs"
45
+ ],
46
+ "engines": {
47
+ "node": ">=14.0.0"
48
+ }
49
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "react-router",
3
+ "version": "7.0.0",
4
+ "description": "Declarative routing for React applications",
5
+ "keywords": [
6
+ "react",
7
+ "router",
8
+ "route",
9
+ "routing",
10
+ "history",
11
+ "link"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/remix-run/react-router",
16
+ "directory": "packages/react-router"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Remix Software <hello@remix.run>",
20
+ "sideEffects": false,
21
+ "main": "./dist/main.js",
22
+ "unpkg": "./dist/umd/react-router.production.min.js",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "dependencies": {
26
+ "@remix-run/router": "2.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "react": "^18.3.1",
30
+ "react-dom": "^18.3.1"
31
+ },
32
+ "peerDependencies": {
33
+ "react": ">=18.0.0",
34
+ "react-dom": ">=18.0.0"
35
+ },
36
+ "files": [
37
+ "dist/",
38
+ "CHANGELOG.md",
39
+ "LICENSE.md",
40
+ "README.md"
41
+ ],
42
+ "engines": {
43
+ "node": ">=18.0.0"
44
+ }
45
+ }
@@ -0,0 +1,102 @@
1
+ import path from 'node:path';
2
+ import { checkVersion, findPackageJson } from '../src/utils';
3
+ import { getBridgeRouterAlias } from '../src/router-alias';
4
+
5
+ const resolveRouterV5 = path.resolve(
6
+ __dirname,
7
+ '../__tests__/mockRouterDir/router-v5/react-router-dom',
8
+ );
9
+ const resolveRouterV5_PkgPath = path.resolve(
10
+ __dirname,
11
+ '../__tests__/mockRouterDir/router-v5/react-router-dom/package.json',
12
+ );
13
+ const resolveRouterV6 = path.resolve(
14
+ __dirname,
15
+ '../__tests__/mockRouterDir/router-v6/react-router-dom/dist/main.js',
16
+ );
17
+ const resolveRouterV6_PkgPath = path.resolve(
18
+ __dirname,
19
+ '../__tests__/mockRouterDir/router-v6/react-router-dom/package.json',
20
+ );
21
+ const resolveRouterV7 = path.resolve(
22
+ __dirname,
23
+ '../__tests__/mockRouterDir/router-v7/react-router',
24
+ );
25
+ const resolveRouterV7_PkgPath = path.resolve(
26
+ __dirname,
27
+ '../__tests__/mockRouterDir/router-v7/react-router/package.json',
28
+ );
29
+
30
+ describe('test checkVersion: should return the correct major version for react-router-dom', () => {
31
+ it('should return 5', () => {
32
+ expect(checkVersion('5.0.0')).toBe(5);
33
+ });
34
+
35
+ it('should return 5', () => {
36
+ expect(checkVersion('^5.0.0')).toBe(5);
37
+ });
38
+
39
+ it('should return 6', () => {
40
+ expect(checkVersion('6.0.0')).toBe(6);
41
+ });
42
+
43
+ it('should return 6', () => {
44
+ expect(checkVersion('~6.0.0')).toBe(6);
45
+ });
46
+
47
+ it('should return 6', () => {
48
+ expect(checkVersion('^6.0.0')).toBe(6);
49
+ });
50
+
51
+ it('should return 7', () => {
52
+ expect(checkVersion('7.0.0')).toBe(7);
53
+ });
54
+
55
+ it('should return 7', () => {
56
+ expect(checkVersion('~7.0.0')).toBe(7);
57
+ });
58
+
59
+ it('should return 7', () => {
60
+ expect(checkVersion('^7.0.0')).toBe(7);
61
+ });
62
+ });
63
+
64
+ describe('test findPackageJson: should return the correct package.json path for react-router-dom v5, v6 and react-router v7', () => {
65
+ it('should return the package.json path', () => {
66
+ expect(findPackageJson(resolveRouterV5)).toBe(resolveRouterV5_PkgPath);
67
+ expect(findPackageJson(resolveRouterV6)).toBe(resolveRouterV6_PkgPath);
68
+ expect(findPackageJson(resolveRouterV7)).toBe(resolveRouterV7_PkgPath);
69
+ });
70
+ });
71
+
72
+ describe('test getBridgeRouterAlias: should return the correct alias for react-router-dom v5, v6 and react-router v7', () => {
73
+ it('should return the correct alias for router v5', () => {
74
+ const res = getBridgeRouterAlias(resolveRouterV5);
75
+ expect(res).toEqual({
76
+ 'react-router-dom$':
77
+ '@module-federation/bridge-react/dist/router-v5.es.js',
78
+ 'react-router-dom/index.js': resolveRouterV5,
79
+ });
80
+ });
81
+
82
+ it('should return the correct alias for router v6', () => {
83
+ const res = getBridgeRouterAlias(resolveRouterV6);
84
+ expect(res).toEqual({
85
+ 'react-router-dom$':
86
+ '@module-federation/bridge-react/dist/router-v6.es.js',
87
+ 'react-router-dom/dist/index.js': resolveRouterV6,
88
+ });
89
+ });
90
+
91
+ it('should return the correct alias for router v7', () => {
92
+ const res = getBridgeRouterAlias(resolveRouterV7);
93
+ expect(res).toEqual({
94
+ 'react-router$': '@module-federation/bridge-react/dist/router-v7.es.js',
95
+ 'react-router-dom$':
96
+ '@module-federation/bridge-react/dist/router-v7.es.js',
97
+ 'react-router/dist/development/index.js': resolveRouterV7,
98
+ 'react-router/dist/production/index.js': resolveRouterV7,
99
+ 'react-router-dom/dist/index.js': resolveRouterV7,
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,14 @@
1
+ import { moduleFederationPlugin } from '@module-federation/sdk';
2
+
3
+ declare class ReactBridgeAliasChangerPlugin {
4
+ alias: string;
5
+ targetFile: string;
6
+ moduleFederationOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
7
+ constructor(info: {
8
+ moduleFederationOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
9
+ });
10
+ apply(compiler: any): void;
11
+ }
12
+ export default ReactBridgeAliasChangerPlugin;
13
+
14
+ export { }