Skip to content

Commit bdda64f

Browse files
authored
docs: add rsbuild doc (#3072)
1 parent 7187626 commit bdda64f

File tree

5 files changed

+173
-3
lines changed

5 files changed

+173
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["runtime", "rspack", "webpack", "vite", "chrome-devtool", "type-prompt", "error-catalog"]
1+
["runtime", "rspack", "webpack", "rsbuild", "vite", "chrome-devtool", "type-prompt", "error-catalog"]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Rsbuild Plugin
2+
3+
Help users quickly build Module Federation products in **Rsbuild App** or **Rslib**
4+
5+
## Quick Start
6+
7+
### Installation
8+
9+
You can install the plugin using the following command:
10+
11+
import { PackageManagerTabs } from '@theme';
12+
13+
<PackageManagerTabs
14+
command={{
15+
npm: 'npm add @module-federation/rsbuild-plugin --save-dev',
16+
yarn: 'yarn add @module-federation/rsbuild-plugin --save-dev',
17+
pnpm: 'pnpm add @module-federation/rsbuild-plugin --save-dev',
18+
bun: 'bun add @module-federation/rsbuild-plugin --save-dev',
19+
}}
20+
/>
21+
22+
### Register plugin
23+
#### Rsbuild App
24+
```ts title='rsbuild.config.ts'
25+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
26+
import { defineConfig } from '@rsbuild/core';
27+
import { pluginReact } from '@rsbuild/plugin-react';
28+
29+
export default defineConfig({
30+
server: {
31+
port: 2000,
32+
},
33+
plugins: [
34+
pluginReact(),
35+
pluginModuleFederation({
36+
name: 'federation_consumer',
37+
remotes: {
38+
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
39+
},
40+
shared: ['react', 'react-dom'],
41+
}),
42+
],
43+
});
44+
```
45+
46+
#### Rslib Module
47+
``` ts title='rslib.config.ts'
48+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
49+
import { defineConfig } from '@rslib/core';
50+
51+
export default defineConfig({
52+
lib: [
53+
// ...
54+
{
55+
format: 'mf',
56+
output: {
57+
distPath: {
58+
root: './dist/mf',
59+
},
60+
assetPrefix: 'xxx',
61+
},
62+
plugins: [
63+
// ...
64+
pluginModuleFederation({
65+
name: 'rslib_provider',
66+
exposes: {
67+
'.': './src/index.tsx',
68+
},
69+
shared: {
70+
react: {
71+
singleton: true,
72+
},
73+
'react-dom': {
74+
singleton: true,
75+
},
76+
},
77+
}),
78+
],
79+
},
80+
],
81+
});
82+
```
83+
84+
### Note
85+
If you need to use the Module Federation runtime capabilities, please install [@module-federation/enhanced](/en/guide/basic/runtime.html)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["runtime", "rspack", "webpack", "vite", "chrome-devtool", "type-prompt"]
1+
["runtime", "rspack", "webpack", "rsbuild", "vite", "chrome-devtool", "type-prompt"]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Rsbuild Plugin
2+
3+
帮助用户快速在 **Rsbuild App****Rslib** 中构建 Module Federation 产物
4+
5+
## 快速开始
6+
7+
### 安装
8+
9+
你可以通过如下的命令安装插件:
10+
11+
import { PackageManagerTabs } from '@theme';
12+
13+
<PackageManagerTabs
14+
command={{
15+
npm: 'npm add @module-federation/rsbuild-plugin --save-dev',
16+
yarn: 'yarn add @module-federation/rsbuild-plugin --save-dev',
17+
pnpm: 'pnpm add @module-federation/rsbuild-plugin --save-dev',
18+
bun: 'bun add @module-federation/rsbuild-plugin --save-dev',
19+
}}
20+
/>
21+
22+
### 注册插件
23+
#### Rsbuild App
24+
```ts title='rsbuild.config.ts'
25+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
26+
import { defineConfig } from '@rsbuild/core';
27+
import { pluginReact } from '@rsbuild/plugin-react';
28+
29+
export default defineConfig({
30+
server: {
31+
port: 2000,
32+
},
33+
plugins: [
34+
pluginReact(),
35+
pluginModuleFederation({
36+
name: 'federation_consumer',
37+
remotes: {
38+
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
39+
},
40+
shared: ['react', 'react-dom'],
41+
}),
42+
],
43+
});
44+
```
45+
46+
#### Rslib Module
47+
``` ts title='rslib.config.ts'
48+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
49+
import { defineConfig } from '@rslib/core';
50+
51+
export default defineConfig({
52+
lib: [
53+
// ...
54+
{
55+
format: 'mf',
56+
output: {
57+
distPath: {
58+
root: './dist/mf',
59+
},
60+
assetPrefix: 'xxx',
61+
},
62+
plugins: [
63+
// ...
64+
pluginModuleFederation({
65+
name: 'rslib_provider',
66+
exposes: {
67+
'.': './src/index.tsx',
68+
},
69+
shared: {
70+
react: {
71+
singleton: true,
72+
},
73+
'react-dom': {
74+
singleton: true,
75+
},
76+
},
77+
}),
78+
],
79+
},
80+
],
81+
});
82+
```
83+
84+
### 注意
85+
如果需要使用 Module Federation 运行时能力,请安装 [@module-federation/enhanced](/zh/guide/basic/runtime.html)

packages/rsbuild-plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineConfig({
3131
}),
3232
],
3333
});
34-
```js
34+
```
3535

3636
### Rslib Module
3737
``` js

0 commit comments

Comments
 (0)