@@ -2,6 +2,7 @@ import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-p
22import  {  getFederationGlobalScope  }  from  './utils' ; 
33import  type  RuntimeGlobals  from  'webpack/lib/RuntimeGlobals' ; 
44import  {  NormalizedRuntimeInitOptionsWithOutShared  }  from  '../../../types/runtime' ; 
5+ import  type  {  RemoteInfos  }  from  '@module-federation/webpack-bundler-runtime' ; 
56
67const  {  Template }  =  require ( 
78  normalizeWebpackPath ( 'webpack' ) , 
@@ -15,7 +16,29 @@ function getFederationGlobal(
1516  initOptionsWithoutShared : NormalizedRuntimeInitOptionsWithOutShared , 
1617) : string  { 
1718  const  federationGlobal  =  getFederationGlobalScope ( runtimeGlobals ) ; 
18-   const  initOptionsStrWithoutShared  =  JSON . stringify ( initOptionsWithoutShared ) ; 
19+   const  initOptionsStrWithoutShared  =  JSON . stringify ( { 
20+     ...initOptionsWithoutShared , 
21+     remotes : initOptionsWithoutShared . remotes . filter ( 
22+       ( remote )  =>  remote . externalType  ===  'script' , 
23+     ) , 
24+   } ) ; 
25+   const  remoteInfos  =  JSON . stringify ( 
26+     initOptionsWithoutShared . remotes . reduce ( ( acc ,  remote )  =>  { 
27+       const  item : RemoteInfos [ string ] [ 0 ]  =  { 
28+         alias : remote . alias  ||  '' , 
29+         name : remote . name , 
30+         // @ts -ignore 
31+         entry : remote . entry  ||  '' , 
32+         // @ts -ignore 
33+         shareScope : remote . shareScope , 
34+         externalType : remote . externalType , 
35+       } ; 
36+       const  key  =  remote . name  ||  remote . alias  ||  '' ; 
37+       acc [ key ]  ||=  [ ] ; 
38+       acc [ key ] . push ( item ) ; 
39+       return  acc ; 
40+     } ,  { }  as  RemoteInfos ) , 
41+   ) ; 
1942
2043  return  template . asString ( [ 
2144    `if(!${ federationGlobal }  , 
@@ -25,11 +48,12 @@ function getFederationGlobal(
2548        `initOptions: ${ initOptionsStrWithoutShared }  , 
2649        `chunkMatcher: function(chunkId) {return ${ matcher }  , 
2750        `rootOutputDir: ${ JSON . stringify ( rootOutputDir  ||  '' ) }  , 
28-         `initialConsumes: undefined,` , 
29-         'bundlerRuntimeOptions: {}' , 
51+         `bundlerRuntimeOptions: { remotes: { remoteInfos: ${ remoteInfos } ${ runtimeGlobals . require }  , 
3052      ] ) , 
3153      '};' , 
3254    ] ) , 
55+     `${ runtimeGlobals . require }  , 
56+     `${ runtimeGlobals . require }  , 
3357    '}' , 
3458  ] ) ; 
3559} 
0 commit comments