MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/container/ContainerReferencePlugin.js:40–153  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

parseOptionsFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
isArrayMethod · 0.80
sliceMethod · 0.80
addRuntimeModuleMethod · 0.80
applyMethod · 0.65
requireFunction · 0.50
setMethod · 0.45
addMethod · 0.45
getCompilationHooksMethod · 0.45

Tested by

no test coverage detected