| | |
| | | const isValidExternalsType = require("../../schemas/plugins/container/ExternalsType.check"); |
| | | 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("../Dependency")} Dependency */ |
| | | |
| | | /** |
| | | * Defines the compilation hooks type used by this module. |
| | | * @typedef {object} CompilationHooks |
| | | * @property {SyncHook<Dependency>} addContainerEntryDependency |
| | | * @property {SyncHook<Dependency>} addFederationRuntimeDependency |
| | | */ |
| | | |
| | | const validate = createSchemaValidation( |
| | | require("../../schemas/plugins/container/ModuleFederationPlugin.check"), |
| | | () => require("../../schemas/plugins/container/ModuleFederationPlugin.json"), |
| | | { |
| | | name: "Module Federation Plugin", |
| | | baseDataPath: "options" |
| | | } |
| | | ); |
| | | |
| | | /** @type {WeakMap<Compilation, CompilationHooks>} */ |
| | | const compilationHooksMap = new WeakMap(); |
| | |
| | | |
| | | class ModuleFederationPlugin { |
| | | /** |
| | | * Creates an instance of ModuleFederationPlugin. |
| | | * @param {ModuleFederationPluginOptions} options options |
| | | */ |
| | | constructor(options) { |
| | | validate(options); |
| | | |
| | | this._options = options; |
| | | /** @type {ModuleFederationPluginOptions} */ |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | | apply(compiler) { |
| | | const { _options: options } = this; |
| | | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| | | compiler.validate( |
| | | () => |
| | | require("../../schemas/plugins/container/ModuleFederationPlugin.json"), |
| | | this.options, |
| | | { |
| | | name: "Module Federation Plugin", |
| | | baseDataPath: "options" |
| | | }, |
| | | (options) => |
| | | require("../../schemas/plugins/container/ModuleFederationPlugin.check")( |
| | | options |
| | | ) |
| | | ); |
| | | }); |
| | | const { options } = this; |
| | | const library = options.library || { type: "var", name: options.name }; |
| | | const remoteType = |
| | | options.remoteType || |