@@ -9,6 +9,7 @@ import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
9
9
import type { moduleFederationPlugin } from '@module-federation/sdk' ;
10
10
11
11
const tempDirPath = path . resolve ( process . cwd ( ) , `node_modules/${ TEMP_DIR } ` ) ;
12
+ export const PLUGIN_NAME = 'module-federation-storybook-addon' ;
12
13
// add bootstrap for host project
13
14
const bootstrapPath = path . resolve (
14
15
process . cwd ( ) ,
@@ -27,7 +28,7 @@ const writeBootstrap = (context: string, entryPath: string) => {
27
28
}
28
29
fs . writeFileSync ( bootstrapPath , generateBootstrap ( context , entryPath ) ) ;
29
30
} ;
30
- export const withModuleFederation = async (
31
+ export const withModuleFederation = (
31
32
rsbuildConfig : RsbuildConfig ,
32
33
options : moduleFederationPlugin . ModuleFederationPluginOptions ,
33
34
) => {
@@ -52,36 +53,30 @@ export const withModuleFederation = async (
52
53
// remoteEntry already includes one hmr runtime, and an additional one is not necessary.
53
54
hmr : false ,
54
55
} ,
55
- tools : {
56
- rspack : ( config ) => {
57
- config . output ??= { } ;
58
- config . output . chunkLoadingGlobal =
59
- 'module-federation-storybook-addon' ;
60
- config . plugins ?. push (
61
- new ModuleFederationPlugin ( {
62
- name : options . name || 'module-federation-storybook-addon' ,
63
- shared : {
64
- react : {
65
- singleton : true ,
66
- } ,
67
- 'react-dom' : {
68
- singleton : true ,
69
- } ,
70
- ...options . shared ,
71
- } ,
72
- remotes : {
73
- ...options . remotes ,
74
- } ,
75
- shareStrategy : options . shareStrategy ,
76
- } ) ,
77
- ) ;
78
- return config ;
79
- } ,
80
- } ,
81
56
} ;
82
-
83
57
return mergeRsbuildConfig ( config , mfConfig ) ;
84
58
} ) ;
59
+
60
+ api . modifyBundlerChain ( async ( chain ) => {
61
+ chain . plugin ( PLUGIN_NAME ) . use ( ModuleFederationPlugin , [
62
+ {
63
+ name : options . name || PLUGIN_NAME ,
64
+ shared : {
65
+ react : {
66
+ singleton : true ,
67
+ } ,
68
+ 'react-dom' : {
69
+ singleton : true ,
70
+ } ,
71
+ ...options . shared ,
72
+ } ,
73
+ remotes : {
74
+ ...options . remotes ,
75
+ } ,
76
+ shareStrategy : options . shareStrategy ,
77
+ } ,
78
+ ] ) ;
79
+ } ) ;
85
80
} ,
86
81
} ;
87
82
0 commit comments