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

Method apply

lib/LoaderOptionsPlugin.js:43–82  ·  lib/LoaderOptionsPlugin.js::LoaderOptionsPlugin.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

41 * @returns {void}
42 */
43 apply(compiler) {
44 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
45 compiler.validate(
46 () => require(class="st">"../schemas/plugins/LoaderOptionsPlugin.json"),
47 this.options,
48 {
49 name: class="st">"Loader Options Plugin",
50 baseDataPath: class="st">"options"
51 },
52 (options) =>
53 require(class="st">"../schemas/plugins/LoaderOptionsPlugin.check")(options)
54 );
55 });
56
57 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
58 NormalModule.getCompilationHooks(compilation).loader.tap(
59 PLUGIN_NAME,
60 (context, module) => {
61 const resource = module.resource;
62 if (!resource) return;
63 const i = resource.indexOf(class="st">"?");
64 if (
65 ModuleFilenameHelpers.matchObject(
66 this.options,
67 i < 0 ? resource : resource.slice(0, i)
68 )
69 ) {
70 for (const key of Object.keys(this.options)) {
71 if (key === class="st">"include" || key === class="st">"exclude" || key === class="st">"test") {
72 continue;
73 }
74
75 /** @type {LoaderContext<EXPECTED_ANY> & Record<string, EXPECTED_ANY>} */
76 (context)[key] = this.options[key];
77 }
78 }
79 }
80 );
81 });
82 }
83}
84
85module.exports = LoaderOptionsPlugin;

Callers

nothing calls this directly

Calls 6

tapMethod · 0.80
validateMethod · 0.80
sliceMethod · 0.80
keysMethod · 0.65
requireFunction · 0.50
getCompilationHooksMethod · 0.45

Tested by

no test coverage detected