@@ -32,7 +32,7 @@ export default function (): FederationRuntimePlugin {
32
32
beforeInit ( args ) {
33
33
const { userOptions, shareInfo } = args ;
34
34
const { shared } = userOptions ;
35
-
35
+ if ( ! globalThis . usedChunks ) globalThis . usedChunks = new Set ( ) ;
36
36
if ( shared ) {
37
37
Object . keys ( shared || { } ) . forEach ( ( sharedKey ) => {
38
38
if ( ! shared [ sharedKey ] . strategy ) {
@@ -50,7 +50,7 @@ export default function (): FederationRuntimePlugin {
50
50
51
51
// if (__webpack_runtime_id__ && !__webpack_runtime_id__.startsWith('webpack')) return args;
52
52
const { moduleCache, name } = args . origin ;
53
- const gs = ( globalThis as any ) || new Function ( 'return globalThis' ) ( ) ;
53
+ const gs = new Function ( 'return globalThis' ) ( ) ;
54
54
const attachedRemote = gs [ name ] ;
55
55
if ( attachedRemote ) {
56
56
moduleCache . set ( name , attachedRemote ) ;
@@ -70,9 +70,35 @@ export default function (): FederationRuntimePlugin {
70
70
afterResolve ( args ) {
71
71
return args ;
72
72
} ,
73
- // onLoad(args) {
74
- // return args;
75
- // },
73
+ onLoad ( args ) {
74
+ const { exposeModuleFactory, exposeModule, id } = args ;
75
+
76
+ const moduleOrFactory = exposeModuleFactory || exposeModule ;
77
+ const exposedModuleExports = moduleOrFactory ( ) ;
78
+ const handler = {
79
+ //@ts -ignore
80
+ get : function ( target , prop , receiver ) {
81
+ const origMethod = target [ prop ] ;
82
+ if ( typeof origMethod === 'function' ) {
83
+ //@ts -ignore
84
+ return function ( ...args ) {
85
+ globalThis . usedChunks . add (
86
+ //@ts -ignore
87
+ id ,
88
+ ) ;
89
+
90
+ // console.log(`function as called to ${prop}`, id);
91
+ //@ts -ignore
92
+ return origMethod . apply ( this , args ) ;
93
+ } ;
94
+ } else {
95
+ return Reflect . get ( target , prop , receiver ) ;
96
+ }
97
+ } ,
98
+ } ;
99
+
100
+ return ( ) => new Proxy ( exposedModuleExports , handler ) ;
101
+ } ,
76
102
resolveShare ( args ) {
77
103
if (
78
104
args . pkgName !== 'react' &&
0 commit comments