From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送

---
 node_modules/webpack/lib/container/ContainerReferencePlugin.js |   69 +++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/node_modules/webpack/lib/container/ContainerReferencePlugin.js b/node_modules/webpack/lib/container/ContainerReferencePlugin.js
index 5b09e1a..cb24257 100644
--- a/node_modules/webpack/lib/container/ContainerReferencePlugin.js
+++ b/node_modules/webpack/lib/container/ContainerReferencePlugin.js
@@ -5,9 +5,9 @@
 
 "use strict";
 
+const ExternalModule = require("../ExternalModule");
 const ExternalsPlugin = require("../ExternalsPlugin");
 const RuntimeGlobals = require("../RuntimeGlobals");
-const createSchemaValidation = require("../util/create-schema-validation");
 const FallbackDependency = require("./FallbackDependency");
 const FallbackItemDependency = require("./FallbackItemDependency");
 const FallbackModuleFactory = require("./FallbackModuleFactory");
@@ -19,49 +19,55 @@
 /** @typedef {import("../../declarations/plugins/container/ContainerReferencePlugin").ContainerReferencePluginOptions} ContainerReferencePluginOptions */
 /** @typedef {import("../Compiler")} Compiler */
 
-const validate = createSchemaValidation(
-	require("../../schemas/plugins/container/ContainerReferencePlugin.check"),
-	() =>
-		require("../../schemas/plugins/container/ContainerReferencePlugin.json"),
-	{
-		name: "Container Reference Plugin",
-		baseDataPath: "options"
-	}
-);
-
 const slashCode = "/".charCodeAt(0);
 const PLUGIN_NAME = "ContainerReferencePlugin";
 
 class ContainerReferencePlugin {
 	/**
+	 * Creates an instance of ContainerReferencePlugin.
 	 * @param {ContainerReferencePluginOptions} options options
 	 */
 	constructor(options) {
-		validate(options);
+		/** @typedef {ContainerReferencePluginOptions} */
+		this.options = options;
+	}
 
-		this._remoteType = options.remoteType;
-		this._remotes = parseOptions(
-			options.remotes,
+	/**
+	 * Applies the plugin by registering its hooks on the compiler.
+	 * @param {Compiler} compiler the compiler instance
+	 * @returns {void}
+	 */
+	apply(compiler) {
+		compiler.hooks.validate.tap(PLUGIN_NAME, () => {
+			compiler.validate(
+				() =>
+					require("../../schemas/plugins/container/ContainerReferencePlugin.json"),
+				this.options,
+				{
+					name: "Container Reference Plugin",
+					baseDataPath: "options"
+				},
+				(options) =>
+					require("../../schemas/plugins/container/ContainerReferencePlugin.check")(
+						options
+					)
+			);
+		});
+
+		const { remoteType } = this.options;
+		const remotes = parseOptions(
+			this.options.remotes,
 			(item) => ({
 				external: Array.isArray(item) ? item : [item],
-				shareScope: options.shareScope || "default"
+				shareScope: this.options.shareScope || "default"
 			}),
 			(item) => ({
 				external: Array.isArray(item.external)
 					? item.external
 					: [item.external],
-				shareScope: item.shareScope || options.shareScope || "default"
+				shareScope: item.shareScope || this.options.shareScope || "default"
 			})
 		);
-	}
-
-	/**
-	 * Apply the plugin
-	 * @param {Compiler} compiler the compiler instance
-	 * @returns {void}
-	 */
-	apply(compiler) {
-		const { _remotes: remotes, _remoteType: remoteType } = this;
 
 		/** @type {Record<string, string>} */
 		const remoteExternals = {};
@@ -131,6 +137,17 @@
 						set.add(RuntimeGlobals.shareScopeMap);
 						compilation.addRuntimeModule(chunk, new RemoteRuntimeModule());
 					});
+
+				const { chunkCondition } =
+					ExternalModule.getCompilationHooks(compilation);
+
+				// External modules issued by remote modules should be placed in entry chunks
+				// to ensure they are loaded and initialize first
+				chunkCondition.tap(
+					PLUGIN_NAME,
+					(chunk, compilation) =>
+						compilation.chunkGraph.getNumberOfEntryModules(chunk) > 0
+				);
 			}
 		);
 	}

--
Gitblit v1.9.3