Skip to content

Add embed runtime again #3651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/slow-cows-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/enhanced': patch
'@module-federation/runtime': patch
---

implement embedded runtime
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ export class HoistContainerReferences implements WebpackPluginInstance {
},
);

// Add modules that reference @module-federation/runtime
compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => {
for (const module of modules) {
// Check if this is a normal module with a resource
if (!('resource' in module) || !module.resource) continue;

// Check module dependencies for @module-federation/runtime references
const mgm = compilation.moduleGraph._getModuleGraphModule(module);
if (!mgm?.outgoingConnections) continue;

for (const connection of mgm.outgoingConnections) {
// Safely check if dependency has a request property and if it includes our target
if (
connection.dependency &&
'request' in connection.dependency &&
typeof connection.dependency.request === 'string' &&
connection.dependency.request.includes(
'@module-federation/runtime',
)
) {
containerEntryDependencies.add(connection.dependency);
break;
}
}
}
});

// Hook into the optimizeChunks phase
compilation.hooks.optimizeChunks.tap(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const RuntimePath = require.resolve('@module-federation/runtime', {
paths: [RuntimeToolsPath],
});

const EmbeddedRuntimePath = require.resolve(
'@module-federation/runtime/embedded',
{
paths: [RuntimeToolsPath],
},
);

const federationGlobal = getFederationGlobalScope(RuntimeGlobals);

const onceForCompiler = new WeakSet<Compiler>();
Expand Down Expand Up @@ -420,6 +427,12 @@ class FederationRuntimePlugin {
if (/webpack-bundler-runtime/.test(resolveData.contextInfo.issuer)) {
resolveData.request = runtimePath;

if (resolveData.createData) {
resolveData.createData.request = resolveData.request;
}
} else {
resolveData.request = EmbeddedRuntimePath;

if (resolveData.createData) {
resolveData.createData.request = resolveData.request;
}
Expand Down
Loading
Loading