Skip to content

Commit 09d6bc1

Browse files
authored
fix(enhanced): use default runtime export (#3601)
1 parent c01715a commit 09d6bc1

File tree

8 files changed

+26
-1132
lines changed

8 files changed

+26
-1132
lines changed

.changeset/chatty-months-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
fix(enhanced): use default runtime export

packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ const BundlerRuntimePath = require.resolve(
4747
const RuntimePath = require.resolve('@module-federation/runtime', {
4848
paths: [RuntimeToolsPath],
4949
});
50-
const EmbeddedRuntimePath = require.resolve(
51-
'@module-federation/runtime/embedded',
52-
{
53-
paths: [RuntimeToolsPath],
54-
},
55-
);
5650

5751
const federationGlobal = getFederationGlobalScope(RuntimeGlobals);
5852

@@ -330,17 +324,28 @@ class FederationRuntimePlugin {
330324
);
331325
}
332326

333-
setRuntimeAlias(compiler: Compiler) {
334-
const { experiments, implementation } = this.options || {};
335-
let runtimePath = EmbeddedRuntimePath;
327+
getRuntimeAlias(compiler: Compiler) {
328+
const { implementation } = this.options || {};
329+
let runtimePath = RuntimePath;
330+
const alias: any = compiler.options.resolve.alias || {};
336331

337-
if (implementation) {
338-
runtimePath = require.resolve(`@module-federation/runtime/embedded`, {
339-
paths: [implementation],
340-
});
332+
if (alias['@module-federation/runtime$']) {
333+
runtimePath = alias['@module-federation/runtime$'];
334+
} else {
335+
if (implementation) {
336+
runtimePath = require.resolve(`@module-federation/runtime`, {
337+
paths: [implementation],
338+
});
339+
}
341340
}
342341

342+
return runtimePath;
343+
}
344+
345+
setRuntimeAlias(compiler: Compiler) {
346+
const { implementation } = this.options || {};
343347
const alias: any = compiler.options.resolve.alias || {};
348+
const runtimePath = this.getRuntimeAlias(compiler);
344349
alias['@module-federation/runtime$'] =
345350
alias['@module-federation/runtime$'] || runtimePath;
346351
alias['@module-federation/runtime-tools$'] =
@@ -408,11 +413,12 @@ class FederationRuntimePlugin {
408413

409414
new HoistContainerReferences().apply(compiler);
410415

416+
const runtimePath = this.getRuntimeAlias(compiler);
411417
new compiler.webpack.NormalModuleReplacementPlugin(
412418
/@module-federation\/runtime/,
413419
(resolveData) => {
414420
if (/webpack-bundler-runtime/.test(resolveData.contextInfo.issuer)) {
415-
resolveData.request = RuntimePath;
421+
resolveData.request = runtimePath;
416422

417423
if (resolveData.createData) {
418424
resolveData.createData.request = resolveData.request;

packages/nextjs-mf/src/plugins/NextFederationPlugin/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ export class NextFederationPlugin {
100100
(message) => /your target environment does not appear/.test(message),
101101
];
102102
}
103-
compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', () => {
104-
compiler.options.resolve.alias = {
105-
...compiler.options.resolve.alias,
106-
//useing embedded runtime
107-
// '@module-federation/runtime$': runtimeESMPath,
108-
};
109-
});
110103
}
111104

112105
private validateOptions(compiler: Compiler): boolean {

0 commit comments

Comments
 (0)