Skip to content

Commit

Permalink
fix: global shared modules into wrapper
Browse files Browse the repository at this point in the history
refs #543
  • Loading branch information
bustEXZ committed Dec 15, 2023
1 parent 76e847a commit 565f601
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/lib/src/prod/remote-production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function prodRemotePlugin(
})
}

const shareScope = options.shareScope || 'default'
return {
name: 'originjs:remote-production',
virtualFile: options.remotes
Expand All @@ -73,11 +74,21 @@ export function prodRemotePlugin(
return module
})
}
function merge(obj1, obj2) {
const mergedObj = Object.assign(obj1, obj2);
for (const key of Object.keys(mergedObj)) {
if (typeof mergedObj[key] === 'object' && typeof obj2[key] === 'object') {
mergedObj[key] = merge(mergedObj[key], obj2[key]);
}
}
return mergedObj;
}
const wrapShareModule = ${REMOTE_FROM_PARAMETER} => {
return {
${getModuleMarker('shareScope')}
}
return merge({
${getModuleMarker('shareScope')}
}, (globalThis.__federation_shared__ || {})['${shareScope}'] || {});
}
async function __federation_import(name) {
Expand Down Expand Up @@ -109,7 +120,7 @@ export function prodRemotePlugin(
getUrl().then(url => {
import(/* @vite-ignore */ url).then(lib => {
if (!remote.inited) {
const shareScope = wrapShareModule(remote.from)
const shareScope = wrapShareModule(remote.from);
lib.init(shareScope);
remote.lib = lib;
remote.lib.init(shareScope);
Expand Down

0 comments on commit 565f601

Please sign in to comment.