* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 38 | * @returns {void} |
| 39 | */ |
| 40 | apply(compiler) { |
| 41 | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| 42 | compiler.validate( |
| 43 | () => |
| 44 | require("../../schemas/plugins/container/ContainerReferencePlugin.json"), |
| 45 | this.options, |
| 46 | { |
| 47 | name: "Container Reference Plugin", |
| 48 | baseDataPath: "options" |
| 49 | }, |
| 50 | (options) => |
| 51 | require("../../schemas/plugins/container/ContainerReferencePlugin.check")( |
| 52 | options |
| 53 | ) |
| 54 | ); |
| 55 | }); |
| 56 | |
| 57 | const { remoteType } = this.options; |
| 58 | const remotes = parseOptions( |
| 59 | this.options.remotes, |
| 60 | (item) => ({ |
| 61 | external: Array.isArray(item) ? item : [item], |
| 62 | shareScope: this.options.shareScope || "default" |
| 63 | }), |
| 64 | (item) => ({ |
| 65 | external: Array.isArray(item.external) |
| 66 | ? item.external |
| 67 | : [item.external], |
| 68 | shareScope: item.shareScope || this.options.shareScope || "default" |
| 69 | }) |
| 70 | ); |
| 71 | |
| 72 | /** @type {Record<string, string>} */ |
| 73 | const remoteExternals = {}; |
| 74 | for (const [key, config] of remotes) { |
| 75 | let i = 0; |
| 76 | for (const external of config.external) { |
| 77 | if (external.startsWith("internal ")) continue; |
| 78 | remoteExternals[ |
| 79 | `webpack/container/reference/${key}${i ? `/fallback-${i}` : ""}` |
| 80 | ] = external; |
| 81 | i++; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | new ExternalsPlugin(remoteType, remoteExternals).apply(compiler); |
| 86 | |
| 87 | compiler.hooks.compilation.tap( |
| 88 | PLUGIN_NAME, |
| 89 | (compilation, { normalModuleFactory }) => { |
| 90 | compilation.dependencyFactories.set( |
| 91 | RemoteToExternalDependency, |
| 92 | normalModuleFactory |
| 93 | ); |
| 94 | |
| 95 | compilation.dependencyFactories.set( |
| 96 | FallbackItemDependency, |
| 97 | normalModuleFactory |
nothing calls this directly
no test coverage detected