* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 43 | * @returns {void} |
| 44 | */ |
| 45 | apply(compiler) { |
| 46 | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| 47 | compiler.validate( |
| 48 | () => |
| 49 | require("../../schemas/plugins/container/ModuleFederationPlugin.json"), |
| 50 | this.options, |
| 51 | { |
| 52 | name: "Module Federation Plugin", |
| 53 | baseDataPath: "options" |
| 54 | }, |
| 55 | (options) => |
| 56 | require("../../schemas/plugins/container/ModuleFederationPlugin.check")( |
| 57 | options |
| 58 | ) |
| 59 | ); |
| 60 | }); |
| 61 | const { options } = this; |
| 62 | const library = options.library || { type: "var", name: options.name }; |
| 63 | const remoteType = |
| 64 | options.remoteType || |
| 65 | (options.library && isValidExternalsType(options.library.type) |
| 66 | ? /** @type {ExternalsType} */ (options.library.type) |
| 67 | : "script"); |
| 68 | if ( |
| 69 | library && |
| 70 | !compiler.options.output.enabledLibraryTypes.includes(library.type) |
| 71 | ) { |
| 72 | compiler.options.output.enabledLibraryTypes.push(library.type); |
| 73 | } |
| 74 | compiler.hooks.afterPlugins.tap(PLUGIN_NAME, () => { |
| 75 | if ( |
| 76 | options.exposes && |
| 77 | (Array.isArray(options.exposes) |
| 78 | ? options.exposes.length > 0 |
| 79 | : Object.keys(options.exposes).length > 0) |
| 80 | ) { |
| 81 | new ContainerPlugin({ |
| 82 | name: /** @type {string} */ (options.name), |
| 83 | library, |
| 84 | filename: options.filename, |
| 85 | runtime: options.runtime, |
| 86 | shareScope: options.shareScope, |
| 87 | exposes: options.exposes |
| 88 | }).apply(compiler); |
| 89 | } |
| 90 | if ( |
| 91 | options.remotes && |
| 92 | (Array.isArray(options.remotes) |
| 93 | ? options.remotes.length > 0 |
| 94 | : Object.keys(options.remotes).length > 0) |
| 95 | ) { |
| 96 | new ContainerReferencePlugin({ |
| 97 | remoteType, |
| 98 | shareScope: options.shareScope, |
| 99 | remotes: options.remotes |
| 100 | }).apply(compiler); |
| 101 | } |
| 102 | if (options.shared) { |