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"

0 commit comments

Comments
 (0)