Skip to content

Commit b41faaa

Browse files
authored
feat: support mf rsbuild plugin (#3062)
1 parent d5a3072 commit b41faaa

File tree

43 files changed

+1349
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1349
-771
lines changed

.changeset/fuzzy-brooms-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/rsbuild-plugin': patch
3+
---
4+
5+
feat: support mf rsbuild plugin #[3062](https://github.com/module-federation/core/pull/3062)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
"@module-federation/bridge-react": "workspace:*",
1313
"@module-federation/enhanced": "workspace:*",
1414
"react-router-dom": "^6.24.1",
15-
"@module-federation/retry-plugin": "workspace:*"
15+
"@module-federation/retry-plugin": "workspace:*",
16+
"react": "^18.3.1",
17+
"react-dom": "^18.3.1"
1618
},
1719
"devDependencies": {
18-
"@rsbuild/core": "^0.6.15",
19-
"@rsbuild/plugin-react": "^0.6.15",
20+
"@module-federation/rsbuild-plugin": "workspace:*",
21+
"@rsbuild/core": "^1.0.7",
22+
"@rsbuild/plugin-react": "^1.0.3",
2023
"@types/react": "^18.2.79",
2124
"@types/react-dom": "^18.3.0",
2225
"tailwindcss": "^3.4.3",
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
1+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
22
import { defineConfig } from '@rsbuild/core';
33
import { pluginReact } from '@rsbuild/plugin-react';
44
import path from 'path';
@@ -14,28 +14,25 @@ export default defineConfig({
1414
server: {
1515
port: 2000,
1616
},
17-
tools: {
18-
rspack: (config, { appendPlugins }) => {
19-
appendPlugins([
20-
new ModuleFederationPlugin({
21-
name: 'federation_consumer',
22-
remotes: {
23-
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
24-
remote2: 'remote2@http://localhost:2002/mf-manifest.json',
25-
remote3: 'remote3@http://localhost:2003/mf-manifest.json',
26-
'remote-render-error':
27-
'remote-render-error@http://localhost:2004/mf-manifest.json',
28-
'remote-resource-error':
29-
'remote-resource-errorr@http://localhost:2008/not-exist-mf-manifest.json',
30-
},
31-
shared: ['react', 'react-dom', 'antd'],
32-
runtimePlugins: [
33-
path.join(__dirname, './src/runtime-plugin/shared-strategy.ts'),
34-
// path.join(__dirname, './src/runtime-plugin/retry.ts'),
35-
],
36-
}),
37-
]);
38-
},
39-
},
40-
plugins: [pluginReact()],
17+
plugins: [
18+
pluginReact(),
19+
pluginModuleFederation({
20+
name: 'federation_consumer',
21+
shareStrategy: 'loaded-first',
22+
remotes: {
23+
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
24+
remote2: 'remote2@http://localhost:2002/mf-manifest.json',
25+
remote3: 'remote3@http://localhost:2003/mf-manifest.json',
26+
'remote-render-error':
27+
'remote-render-error@http://localhost:2004/mf-manifest.json',
28+
'remote-resource-error':
29+
'remote-resource-errorr@http://localhost:2008/not-exist-mf-manifest.json',
30+
},
31+
shared: ['react', 'react-dom', 'antd'],
32+
runtimePlugins: [
33+
path.join(__dirname, './src/runtime-plugin/shared-strategy.ts'),
34+
// path.join(__dirname, './src/runtime-plugin/retry.ts'),
35+
],
36+
}),
37+
],
4138
});

apps/router-demo/router-host-2000/src/App.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { createRemoteComponent } from '@module-federation/bridge-react';
66
import Navigation from './navigation';
77
import Detail from './pages/Detail';
88
import Home from './pages/Home';
9-
import styles from './index.module.less';
109
import './App.css';
1110

1211
init({
@@ -132,14 +131,7 @@ const App = () => {
132131
<Route path="/detail/*" Component={Detail} />
133132
<Route
134133
path="/remote1/*"
135-
Component={() => (
136-
<Remote1App
137-
className={styles.remote1}
138-
name={'Ming'}
139-
age={12}
140-
ref={ref}
141-
/>
142-
)}
134+
Component={() => <Remote1App name={'Ming'} age={12} ref={ref} />}
143135
/>
144136
<Route
145137
path="/remote2/*"

apps/router-demo/router-host-2000/src/index.module.less

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/router-demo/router-host-v5-2200/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"react-router-dom": "^5.3.4"
1919
},
2020
"devDependencies": {
21-
"@rsbuild/core": "^0.6.15",
22-
"@rsbuild/plugin-react": "^0.6.15",
21+
"@module-federation/rsbuild-plugin": "workspace:*",
22+
"@rsbuild/core": "^1.0.7",
23+
"@rsbuild/plugin-react": "^1.0.3",
2324
"@types/react": "^18.2.79",
2425
"@types/react-dom": "^18.3.0",
2526
"tailwindcss": "^3.4.3",
Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
1+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
22
import { defineConfig } from '@rsbuild/core';
33
import { pluginReact } from '@rsbuild/plugin-react';
44
import path from 'path';
@@ -18,24 +18,20 @@ export default defineConfig({
1818
server: {
1919
port: 2200,
2020
},
21-
tools: {
22-
rspack: (config, { appendPlugins }) => {
23-
appendPlugins([
24-
new ModuleFederationPlugin({
25-
name: 'federation_consumer2',
26-
remotes: {
27-
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
28-
remote2: 'remote2@http://localhost:2002/mf-manifest.json',
29-
remote3: 'remote3@http://localhost:2003/mf-manifest.json',
30-
remote_error: 'remote_error@http://localhost:2004/mf-manifest.json',
31-
},
32-
shared: ['react', 'react-dom', 'antd'],
33-
runtimePlugins: [
34-
path.join(__dirname, './src/runtime-plugin/shared-strategy.ts'),
35-
],
36-
}),
37-
]);
38-
},
39-
},
40-
plugins: [pluginReact()],
21+
plugins: [
22+
pluginReact(),
23+
pluginModuleFederation({
24+
name: 'federation_consumer2',
25+
remotes: {
26+
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
27+
remote2: 'remote2@http://localhost:2002/mf-manifest.json',
28+
remote3: 'remote3@http://localhost:2003/mf-manifest.json',
29+
remote_error: 'remote_error@http://localhost:2004/mf-manifest.json',
30+
},
31+
shared: ['react', 'react-dom', 'antd'],
32+
runtimePlugins: [
33+
path.join(__dirname, './src/runtime-plugin/shared-strategy.ts'),
34+
],
35+
}),
36+
],
4137
});

apps/router-demo/router-host-vue3-2100/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"vue-router": "^4.3.2"
1515
},
1616
"devDependencies": {
17-
"@rsbuild/core": "^0.6.15",
18-
"@rsbuild/plugin-vue": "^0.6.15",
17+
"@module-federation/rsbuild-plugin": "workspace:*",
18+
"@rsbuild/core": "^1.0.7",
19+
"@rsbuild/plugin-vue": "^1.0.1",
1920
"tailwindcss": "^3.4.3",
2021
"typescript": "^5.4.2"
2122
}
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from '@rsbuild/core';
22
import { pluginVue } from '@rsbuild/plugin-vue';
3-
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
3+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
44
import path from 'path';
55

66
export default defineConfig({
@@ -19,19 +19,13 @@ export default defineConfig({
1919
assetPrefix: 'http://localhost:2100',
2020
writeToDisk: true,
2121
},
22-
tools: {
23-
rspack: (config, { appendPlugins }) => {
24-
delete config.optimization?.splitChunks;
25-
appendPlugins([
26-
new ModuleFederationPlugin({
27-
name: 'host2',
28-
remotes: {
29-
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
30-
},
31-
}),
32-
]);
33-
},
34-
},
35-
36-
plugins: [pluginVue()],
22+
plugins: [
23+
pluginVue(),
24+
pluginModuleFederation({
25+
name: 'host2',
26+
remotes: {
27+
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
28+
},
29+
}),
30+
],
3731
});

apps/router-demo/router-remote1-2001/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@module-federation/bridge-react": "workspace:*",
12-
"@module-federation/enhanced": "workspace:*",
12+
"@module-federation/rsbuild-plugin": "workspace:*",
1313
"antd": "^5.16.2",
1414
"react": "^18.3.1",
1515
"react-dom": "^18.3.1",
@@ -18,9 +18,9 @@
1818
},
1919
"devDependencies": {
2020
"@ant-design/cssinjs": "^1.20.0",
21-
"@rsbuild/core": "^0.6.15",
22-
"@rsbuild/plugin-react": "^0.6.15",
23-
"@rsbuild/shared": "^0.6.15",
21+
"@rsbuild/core": "^1.0.7",
22+
"@rsbuild/plugin-react": "^1.0.3",
23+
"@rsbuild/shared": "^0.7.10",
2424
"@types/react": "^18.2.79",
2525
"@types/react-dom": "^18.3.0",
2626
"typescript": "^5.4.5"
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
1+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
22
import { defineConfig } from '@rsbuild/core';
33
import { pluginReact } from '@rsbuild/plugin-react';
4-
import { createCacheGroups } from '@rsbuild/shared';
54
import path from 'path';
65

76
export default defineConfig({
@@ -28,31 +27,30 @@ export default defineConfig({
2827
tools: {
2928
rspack: (config, { appendPlugins }) => {
3029
delete config.optimization?.splitChunks;
31-
config.output!.uniqueName = 'router-remote1-2001';
32-
appendPlugins([
33-
new ModuleFederationPlugin({
34-
name: 'remote1',
35-
exposes: {
36-
'./button': './src/button.tsx',
37-
'./export-app': './src/export-App.tsx',
38-
},
39-
shared: {
40-
// react: {
41-
// singleton: true,
42-
// },
43-
// 'react-dom': {
44-
// singleton: true,
45-
// },
46-
// 'react-router-dom': {
47-
// singleton: true,
48-
// },
49-
// antd: {
50-
// singleton: true,
51-
// },
52-
},
53-
}),
54-
]);
5530
},
5631
},
57-
plugins: [pluginReact()],
32+
plugins: [
33+
pluginReact(),
34+
pluginModuleFederation({
35+
name: 'remote1',
36+
exposes: {
37+
'./button': './src/button.tsx',
38+
'./export-app': './src/export-App.tsx',
39+
},
40+
shared: {
41+
// react: {
42+
// singleton: true,
43+
// },
44+
// 'react-dom': {
45+
// singleton: true,
46+
// },
47+
// 'react-router-dom': {
48+
// singleton: true,
49+
// },
50+
// antd: {
51+
// singleton: true,
52+
// },
53+
},
54+
}),
55+
],
5856
});

apps/router-demo/router-remote2-2002/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"@emotion/react": "^11.11.4",
1212
"@emotion/styled": "^11.11.5",
1313
"@module-federation/bridge-react": "workspace:*",
14-
"@module-federation/enhanced": "workspace:*",
14+
"@module-federation/rsbuild-plugin": "workspace:*",
1515
"react": "18.3.1",
1616
"react-dom": "18.3.1",
1717
"react-router-dom": "6.24.1"
1818
},
1919
"devDependencies": {
20-
"@rsbuild/core": "^0.6.15",
21-
"@rsbuild/plugin-react": "^0.6.15",
20+
"@rsbuild/core": "^1.0.7",
21+
"@rsbuild/plugin-react": "^1.0.3",
2222
"@types/react": "^18.2.79",
2323
"@types/react-dom": "^18.3.0",
2424
"typescript": "^5.4.5"

apps/router-demo/router-remote2-2002/rsbuild.config.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
2-
// import { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';
1+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
32
import { defineConfig } from '@rsbuild/core';
43
import { pluginReact } from '@rsbuild/plugin-react';
54
import path from 'path';
@@ -23,20 +22,6 @@ export default defineConfig({
2322
assetPrefix: 'http://localhost:2002',
2423
},
2524
tools: {
26-
rspack: (config, { appendPlugins }) => {
27-
config.output!.uniqueName = 'remote2';
28-
delete config.optimization?.splitChunks;
29-
appendPlugins([
30-
new ModuleFederationPlugin({
31-
name: 'remote2',
32-
exposes: {
33-
'./button': './src/button.tsx',
34-
'./export-app': './src/export-App.tsx',
35-
},
36-
shared: ['react', 'react-dom'],
37-
}),
38-
]);
39-
},
4025
// cssExtract: {
4126
// pluginOptions: {
4227
// insert(element) {
@@ -54,5 +39,15 @@ export default defineConfig({
5439
// },
5540
// },
5641
},
57-
plugins: [pluginReact()],
42+
plugins: [
43+
pluginReact(),
44+
pluginModuleFederation({
45+
name: 'remote2',
46+
exposes: {
47+
'./button': './src/button.tsx',
48+
'./export-app': './src/export-App.tsx',
49+
},
50+
shared: ['react', 'react-dom'],
51+
}),
52+
],
5853
});

apps/router-demo/router-remote3-2003/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
"preview": "rsbuild preview"
99
},
1010
"dependencies": {
11+
"@module-federation/rsbuild-plugin": "workspace:*",
1112
"@module-federation/bridge-vue3": "workspace:*",
12-
"@module-federation/enhanced": "workspace:*",
1313
"vue": "^3.4.19",
1414
"vue-router": "^4.3.2"
1515
},
1616
"devDependencies": {
17-
"@rsbuild/core": "^0.6.15",
18-
"@rsbuild/plugin-vue": "^0.6.15",
17+
"@rsbuild/core": "^1.0.7",
18+
"@rsbuild/plugin-vue": "^1.0.1",
1919
"@vue/tsconfig": "^0.5.1",
2020
"tailwindcss": "^3.4.3",
2121
"typescript": "^5.4.2",

0 commit comments

Comments
 (0)