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

Method apply

lib/container/ContainerPlugin.js:39–120  ·  lib/container/ContainerPlugin.js::ContainerPlugin.apply

* 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

37 * @returns {void}
38 */
39 apply(compiler) {
40 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
41 compiler.validate(
42 () => require(class="st">"../../schemas/plugins/container/ContainerPlugin.json"),
43 this.options,
44 {
45 name: class="st">"Container Plugin",
46 baseDataPath: class="st">"options"
47 },
48 (options) =>
49 require(class="st">"../../schemas/plugins/container/ContainerPlugin.check")(
50 options
51 )
52 );
53 });
54
55 const library = this.options.library || {
56 type: class="st">"var",
57 name: this.options.name
58 };
59
60 if (!compiler.options.output.enabledLibraryTypes.includes(library.type)) {
61 compiler.options.output.enabledLibraryTypes.push(library.type);
62 }
63
64 const exposes = /** @type {ExposesList} */ (
65 parseOptions(
66 this.options.exposes,
67 (item) => ({
68 import: Array.isArray(item) ? item : [item],
69 name: undefined
70 }),
71 (item) => ({
72 import: Array.isArray(item.import) ? item.import : [item.import],
73 name: item.name || undefined
74 })
75 )
76 );
77
78 const shareScope = this.options.shareScope || class="st">"default";
79
80 compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
81 const hooks =
82 getModuleFederationPlugin().getCompilationHooks(compilation);
83 const dep = new ContainerEntryDependency(
84 this.options.name,
85 exposes,
86 shareScope
87 );
88 dep.loc = { name: this.options.name };
89 compilation.addEntry(
90 compilation.options.context,
91 dep,
92 {
93 name: this.options.name,
94 filename: this.options.filename,
95 runtime: this.options.runtime,
96 library

Callers

nothing calls this directly

Calls 11

parseOptionsFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
isArrayMethod · 0.80
addEntryMethod · 0.80
requireFunction · 0.50
callbackFunction · 0.50
pushMethod · 0.45
getCompilationHooksMethod · 0.45
callMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected