diff --git a/.changeset/green-chefs-crash.md b/.changeset/green-chefs-crash.md new file mode 100644 index 00000000000..eff34a08944 --- /dev/null +++ b/.changeset/green-chefs-crash.md @@ -0,0 +1,5 @@ +--- +'@module-federation/enhanced': patch +--- + +fix: intercept legacy entry diff --git a/apps/runtime-demo/3005-runtime-host/webpack.config.js b/apps/runtime-demo/3005-runtime-host/webpack.config.js index 9f9f851cc91..08c063c8e03 100644 --- a/apps/runtime-demo/3005-runtime-host/webpack.config.js +++ b/apps/runtime-demo/3005-runtime-host/webpack.config.js @@ -17,7 +17,28 @@ module.exports = composePlugins(withNx(), withReact(), (config, context) => { name: 'runtime_host', remotes: { // remote2: 'runtime_remote2@http://localhost:3007/remoteEntry.js', - remote1: 'runtime_remote1@http://127.0.0.1:3006/mf-manifest.json', + // remote1: 'runtime_remote1@http://127.0.0.1:3006/mf-manifest.json', + remote1: `promise new Promise((resolve)=>{ + const raw = 'runtime_remote1@http://127.0.0.1:3006/remoteEntry.js' + const [_, remoteUrlWithVersion] = raw.split('@') + const script = document.createElement('script') + script.src = remoteUrlWithVersion + script.onload = () => { + const proxy = { + get: (request) => window.runtime_remote1.get(request), + init: (arg) => { + try { + return window.runtime_remote1.init(arg) + } catch(e) { + console.log('runtime_remote1 container already initialized') + } + } + } + resolve(proxy) + } + document.head.appendChild(script); + + })`, }, // library: { type: 'var', name: 'runtime_remote' }, filename: 'remoteEntry.js', diff --git a/packages/enhanced/src/lib/container/runtime/utils.ts b/packages/enhanced/src/lib/container/runtime/utils.ts index 8639ca6f9b9..6307b5d6059 100644 --- a/packages/enhanced/src/lib/container/runtime/utils.ts +++ b/packages/enhanced/src/lib/container/runtime/utils.ts @@ -51,6 +51,10 @@ export function normalizeRuntimeInitOptionsWithOutShared( const { external, shareScope } = remoteInfos; try { // only fit for remoteType: 'script' + const entry = external[0]; + if (/\s/.test(entry)) { + return; + } const [url, globalName] = extractUrlAndGlobal(external[0]); remoteOptions.push({ alias,