From 8179eec60e5c2574cf1a1bafafc5e1c5ce3f9b79 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Mon, 6 May 2024 20:26:39 +0800 Subject: [PATCH] fix(mf): __webpack_init_sharing__ with empty config (#6450) --- .../container-1-0/init-sharing-without-config/index.js | 4 ++++ .../init-sharing-without-config/webpack.config.js | 8 ++++++++ packages/rspack/src/container/ModuleFederationPluginV1.ts | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js diff --git a/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js new file mode 100644 index 00000000000..4ba156ad866 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js @@ -0,0 +1,4 @@ +it("should have single runtime chunk", () => { + __webpack_init_sharing__("default"); + expect(typeof __webpack_require__.I).toBe("function") +}); diff --git a/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js new file mode 100644 index 00000000000..3588b01b231 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js @@ -0,0 +1,8 @@ +const { ModuleFederationPluginV1: ModuleFederationPlugin } = require("@rspack/core").container; + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + plugins: [ + new ModuleFederationPlugin({}), + ] +}; diff --git a/packages/rspack/src/container/ModuleFederationPluginV1.ts b/packages/rspack/src/container/ModuleFederationPluginV1.ts index c86c9bc7085..1bcd18c4213 100644 --- a/packages/rspack/src/container/ModuleFederationPluginV1.ts +++ b/packages/rspack/src/container/ModuleFederationPluginV1.ts @@ -9,6 +9,7 @@ import { SharePlugin, Shared } from "../sharing/SharePlugin"; import { isValidate } from "../util/validate"; import { ContainerPlugin, Exposes } from "./ContainerPlugin"; import { ContainerReferencePlugin, Remotes } from "./ContainerReferencePlugin"; +import { ShareRuntimePlugin } from "../sharing/ShareRuntimePlugin"; export interface ModuleFederationPluginV1Options { exposes?: Exposes; @@ -43,6 +44,7 @@ export class ModuleFederationPluginV1 { compiler.options.output.enabledLibraryTypes!.push(library.type); } compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => { + new ShareRuntimePlugin(this._options.enhanced).apply(compiler); if ( options.exposes && (Array.isArray(options.exposes)