Skip to content

Commit

Permalink
fix: loading of 2nd level MF2 remotes (#856)
Browse files Browse the repository at this point in the history
* fix: use default library config

* fix: noop handler for generatePreloadAssets

* chore: add changset
  • Loading branch information
jbroma authored Jan 8, 2025
1 parent 4e0253a commit 9570c83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-lamps-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Fix loading of 2nd level Module Federation 2 remotes
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const RepackCorePlugin: () => FederationRuntimePlugin = () => ({
console.error(`Failed to load remote entry: ${entryGlobalName}`);
}
},
generatePreloadAssets: async () => {
// noop for compatibility
return Promise.resolve({
cssAssets: [],
jsAssetsWithoutEntry: [],
entryAssets: [],
});
},
});

export default RepackCorePlugin;
13 changes: 4 additions & 9 deletions packages/repack/src/plugins/ModuleFederationPluginV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,6 @@ export class ModuleFederationPluginV2 implements RspackPluginInstance {

const ModuleFederationPlugin = this.getModuleFederationPlugin(compiler);

const libraryConfig = this.config.exposes
? {
name: this.config.name,
type: 'self',
...this.config.library,
}
: undefined;

const sharedConfig = this.adaptSharedDependencies(
this.config.shared ?? this.getDefaultSharedDependencies()
);
Expand All @@ -284,9 +276,12 @@ export class ModuleFederationPluginV2 implements RspackPluginInstance {
this.config.runtimePlugins
);

// NOTE: we keep the default library config since it's the most compatible
// Default library config uses 'externalType': 'script' and 'type': 'var'
// var works identical to 'self' since declaring var in a global scope is
// equal to assigning to the globalObject (normalized by Re.Pack to 'self')
const config: MF.ModuleFederationPluginOptions = {
...this.config,
library: libraryConfig,
shared: sharedConfig,
shareStrategy: shareStrategyConfig,
runtimePlugins: runtimePluginsConfig,
Expand Down

0 comments on commit 9570c83

Please sign in to comment.