feat: refactoring project
This commit is contained in:
39
node_modules/webpack/lib/container/ModuleFederationPlugin.js
generated
vendored
39
node_modules/webpack/lib/container/ModuleFederationPlugin.js
generated
vendored
@@ -5,16 +5,26 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const { SyncHook } = require("tapable");
|
||||
const isValidExternalsType = require("../../schemas/plugins/container/ExternalsType.check.js");
|
||||
const Compilation = require("../Compilation");
|
||||
const SharePlugin = require("../sharing/SharePlugin");
|
||||
const createSchemaValidation = require("../util/create-schema-validation");
|
||||
const ContainerPlugin = require("./ContainerPlugin");
|
||||
const ContainerReferencePlugin = require("./ContainerReferencePlugin");
|
||||
const HoistContainerReferences = require("./HoistContainerReferencesPlugin");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ExternalsType} ExternalsType */
|
||||
/** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ModuleFederationPluginOptions} ModuleFederationPluginOptions */
|
||||
/** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").Shared} Shared */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
|
||||
/**
|
||||
* @typedef {object} CompilationHooks
|
||||
* @property {SyncHook<Dependency>} addContainerEntryDependency
|
||||
* @property {SyncHook<Dependency>} addFederationRuntimeDependency
|
||||
*/
|
||||
|
||||
const validate = createSchemaValidation(
|
||||
require("../../schemas/plugins/container/ModuleFederationPlugin.check.js"),
|
||||
@@ -24,6 +34,10 @@ const validate = createSchemaValidation(
|
||||
baseDataPath: "options"
|
||||
}
|
||||
);
|
||||
|
||||
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
||||
const compilationHooksMap = new WeakMap();
|
||||
|
||||
class ModuleFederationPlugin {
|
||||
/**
|
||||
* @param {ModuleFederationPluginOptions} options options
|
||||
@@ -34,6 +48,28 @@ class ModuleFederationPlugin {
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the compilation hooks associated with this plugin.
|
||||
* @param {Compilation} compilation The compilation instance.
|
||||
* @returns {CompilationHooks} The hooks for the compilation.
|
||||
*/
|
||||
static getCompilationHooks(compilation) {
|
||||
if (!(compilation instanceof Compilation)) {
|
||||
throw new TypeError(
|
||||
"The 'compilation' argument must be an instance of Compilation"
|
||||
);
|
||||
}
|
||||
let hooks = compilationHooksMap.get(compilation);
|
||||
if (!hooks) {
|
||||
hooks = {
|
||||
addContainerEntryDependency: new SyncHook(["dependency"]),
|
||||
addFederationRuntimeDependency: new SyncHook(["dependency"])
|
||||
};
|
||||
compilationHooksMap.set(compilation, hooks);
|
||||
}
|
||||
return hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
@@ -61,7 +97,7 @@ class ModuleFederationPlugin {
|
||||
: Object.keys(options.exposes).length > 0)
|
||||
) {
|
||||
new ContainerPlugin({
|
||||
name: options.name,
|
||||
name: /** @type {string} */ (options.name),
|
||||
library,
|
||||
filename: options.filename,
|
||||
runtime: options.runtime,
|
||||
@@ -87,6 +123,7 @@ class ModuleFederationPlugin {
|
||||
shareScope: options.shareScope
|
||||
}).apply(compiler);
|
||||
}
|
||||
new HoistContainerReferences().apply(compiler);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user