@@ -30,14 +30,15 @@ import { PackageManagerTabs } from '@theme';
3030
3131然后在 ` rslib.config.ts ` 中注册插件:
3232
33- ``` ts title='rslib.config.ts' {8-43}
33+ ``` ts title='rslib.config.ts'
3434import { pluginModuleFederation } from ' @module-federation/rsbuild-plugin' ;
3535import { pluginReact } from ' @rsbuild/plugin-react' ;
3636import { defineConfig } from ' @rslib/core' ;
3737
3838export default defineConfig ({
3939 lib: [
4040 // ... 其他 format
41+ // [!code highlight:35]
4142 {
4243 format: ' mf' ,
4344 output: {
@@ -116,31 +117,31 @@ Rslib 支持宿主应用和 Rslib 模块联邦项目同时开发。
116117设置宿主应用消费 Rslib 的模块联邦库。查看[ @module-federation/rsbuild-plugin
117118] ( https://www.npmjs.com/package/@module-federation/rsbuild-plugin ) 获取更多信息。
118119
119- ``` ts title="rsbuild.config.ts" {8-24}
120+ ``` ts title="rsbuild.config.ts"
120121import { pluginModuleFederation } from ' @module-federation/rsbuild-plugin' ;
121122import { defineConfig } from ' @rsbuild/core' ;
122123import { pluginReact } from ' @rsbuild/plugin-react' ;
123124
124125export default defineConfig ({
125126 plugins: [
126127 pluginReact (),
127- pluginModuleFederation ({
128- name: ' rsbuild_host' ,
129- remotes: {
130- rslib: ' rslib@http://localhost:3001/mf/mf-manifest.json' ,
131- },
132- shared: {
133- react: {
134- singleton: true ,
135- },
136- ' react-dom' : {
137- singleton: true ,
138- },
139- },
140- // 开启这个当 Rslib 产物为 'production' 模式, 但是宿主应用是 'development' 模式。
141- // 参考链接: https://lib.rsbuild.dev/guide/advanced/module-federation#faqs
142- shareStrategy: ' loaded-first' ,
143- }),
128+ pluginModuleFederation ({ // [!code highlight]
129+ name: ' rsbuild_host' , // [!code highlight]
130+ remotes: { // [!code highlight]
131+ rslib: ' rslib@http://localhost:3001/mf/mf-manifest.json' , // [!code highlight]
132+ }, // [!code highlight]
133+ shared: { // [!code highlight]
134+ react: { // [!code highlight]
135+ singleton: true , // [!code highlight]
136+ }, // [!code highlight]
137+ ' react-dom' : { // [!code highlight]
138+ singleton: true , // [!code highlight]
139+ }, // [!code highlight]
140+ }, // [!code highlight]
141+ // 开启这个当 Rslib 产物为 'production' 模式, 但是宿主应用是 'development' 模式。 // [!code highlight]
142+ // 参考链接: https://lib.rsbuild.dev/guide/advanced/module-federation#faqs // [!code highlight]
143+ shareStrategy: ' loaded-first' , // [!code highlight]
144+ }), // [!code highlight]
144145 ],
145146});
146147```
@@ -181,7 +182,7 @@ Rslib 支持使用 Storybook 开发 Rslib 模块联邦项目。
181182
1821832 . 然后创建 Storybook 配置文件 ` .storybook/main.ts ` ,指定 stories 和 addons,并设置 framework 和相应的 framework 集成。
183184
184- ``` ts title=".storybook/main.ts" {18-38}
185+ ``` ts title=".storybook/main.ts"
185186import { dirname , join } from ' node:path' ;
186187import type { StorybookConfig } from ' storybook-react-rsbuild' ;
187188
@@ -199,7 +200,7 @@ const config: StorybookConfig = {
199200 options: {},
200201 },
201202 addons: [
202- {
203+ { // [!code highlight:20]
203204 name: getAbsolutePath (' storybook-addon-rslib' ),
204205 options: {
205206 rslib: {
@@ -230,10 +231,10 @@ export default config;
230231
231232从远程模块引入组件
232233
233- ``` ts title="stories/index.stories.tsx" {2-3}
234+ ``` ts title="stories/index.stories.tsx"
234235import React from ' react' ;
235- // 在这里加载远程模块,Storybook 相当于宿主应用.
236- import { Counter } from ' rslib-module' ;
236+ // 在这里加载远程模块,Storybook 相当于宿主应用. // [!code highlight]
237+ import { Counter } from ' rslib-module' ; // [!code highlight]
237238
238239const Component = () => <Counter />;
239240
0 commit comments