Skip to content

Commit 5a34b5e

Browse files
authored
docs: fix rspack config demo (#2446)
1 parent 682547d commit 5a34b5e

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

apps/website-new/docs/en/guide/basic/rspack.mdx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,37 @@ import { PackageManagerTabs } from '@theme';
3232
In `Rspack`, you can add the plugin through the `plugins` configuration item in the `rspack.config.js` file:
3333

3434
```ts title='rspack.config.js'
35+
import { defineConfig } from '@rsbuild/core';
3536
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
36-
module.exports = {
37-
devServer: {
38-
port: 2000,
37+
38+
export default defineConfig({
39+
// publicPath must be configured if using manifest
40+
dev: {
41+
assetPrefix: 'http://localhost:2000/',
3942
},
4043
output: {
41-
// publicPath must be configured if using manifest
42-
publicPath: 'http://localhost:2000/',
44+
// This will affect the build output resource url prefix in production env
45+
assetPrefix: 'https://cdn.domain.com/path/to/project/',
4346
},
44-
plugins: [
45-
new ModuleFederationPlugin({
46-
name: 'rspack_provider',
47-
filename: 'remoteEntry.js',
48-
exposes: {
49-
// Set the modules to be exported, default export as '.'
50-
'./button': './src/components/button',
51-
},
52-
shared: {
53-
react: {
54-
singleton: true,
55-
},
56-
'react-dom': {
57-
singleton: true,
58-
},
59-
},
60-
}),
61-
],
62-
};
47+
server: {
48+
port: 2000,
49+
},
50+
tools: {
51+
rspack: (config, { appendPlugins }) => {
52+
// You need to set a unique value that is not equal to other applications
53+
config.output!.uniqueName = 'federation_provider';
54+
appendPlugins([
55+
new ModuleFederationPlugin({
56+
name: 'federation_provider',
57+
exposes: {
58+
'./button': './src/button.tsx',
59+
},
60+
shared: ['react', 'react-dom'],
61+
}),
62+
]);
63+
},
64+
},
65+
});
6366
```
6467

6568
## Configure the Build Plugin

apps/website-new/docs/zh/guide/basic/rspack.mdx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,37 @@ import { PackageManagerTabs } from '@theme';
3232
`Rspack` 中,你可以通过 `rspack.config.js` 配置文件中的 `plugins` 配置项来添加插件:
3333

3434
```ts title='rspack.config.js'
35+
import { defineConfig } from '@rsbuild/core';
3536
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
36-
module.exports = {
37-
devServer: {
38-
port: 2000,
37+
38+
export default defineConfig({
39+
// 使用 manifest 必须要配置 publicPath
40+
dev: {
41+
assetPrefix: 'http://localhost:2000/',
3942
},
4043
output: {
41-
// 使用 manifest 必须要配置 publicPath
42-
publicPath: 'http://localhost:2000/',
44+
// 这将影响生产环境中使用的产物路径前缀
45+
assetPrefix: 'https://cdn.domain.com/path/to/project/',
4346
},
44-
plugins: [
45-
new ModuleFederationPlugin({
46-
name: 'rspack_provider',
47-
filename: 'remoteEntry.js',
48-
exposes: {
49-
// 设置需要导出的模块,default 导出为 .
50-
'./button': './src/components/button',
51-
},
52-
shared: {
53-
react: {
54-
singleton: true,
55-
},
56-
'react-dom': {
57-
singleton: true,
58-
},
59-
},
60-
}),
61-
],
62-
};
47+
server: {
48+
port: 2000,
49+
},
50+
tools: {
51+
rspack: (config, { appendPlugins }) => {
52+
// 需要设置一个唯一值不能和其他应用相等
53+
config.output!.uniqueName = 'federation_provider';
54+
appendPlugins([
55+
new ModuleFederationPlugin({
56+
name: 'federation_provider',
57+
exposes: {
58+
'./button': './src/button.tsx',
59+
},
60+
shared: ['react', 'react-dom'],
61+
}),
62+
]);
63+
},
64+
},
65+
});
6366
```
6467

6568
## 配置构建插件

0 commit comments

Comments
 (0)