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

Method apply

lib/dependencies/RequireContextPlugin.js:33–165  ·  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

31 * @returns {void}
32 */
33 apply(compiler) {
34 compiler.hooks.compilation.tap(
35 PLUGIN_NAME,
36 (compilation, { contextModuleFactory, normalModuleFactory }) => {
37 compilation.dependencyFactories.set(
38 RequireContextDependency,
39 contextModuleFactory
40 );
41 compilation.dependencyTemplates.set(
42 RequireContextDependency,
43 new RequireContextDependency.Template()
44 );
45
46 compilation.dependencyFactories.set(
47 ContextElementDependency,
48 normalModuleFactory
49 );
50
51 /**
52 * Handles the hook callback for this code path.
53 * @param {Parser} parser parser parser
54 * @param {JavascriptParserOptions} parserOptions parserOptions
55 * @returns {void}
56 */
57 const handler = (parser, parserOptions) => {
58 if (
59 parserOptions.requireContext !== undefined &&
60 !parserOptions.requireContext
61 ) {
62 return;
63 }
64
65 new RequireContextDependencyParserPlugin().apply(parser);
66 };
67
68 normalModuleFactory.hooks.parser
69 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
70 .tap(PLUGIN_NAME, handler);
71 normalModuleFactory.hooks.parser
72 .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
73 .tap(PLUGIN_NAME, handler);
74
75 contextModuleFactory.hooks.alternativeRequests.tap(
76 PLUGIN_NAME,
77 (items, options) => {
78 if (items.length === 0) return items;
79
80 const finalResolveOptions = compiler.resolverFactory.get(
81 "normal",
82 cachedSetProperty(
83 options.resolveOptions || EMPTY_RESOLVE_OPTIONS,
84 "dependencyType",
85 /** @type {string} */
86 (options.category)
87 )
88 ).options;
89
90 /** @type {{ context: string, request: string }[]} */

Callers

nothing calls this directly

Calls 8

cachedSetPropertyFunction · 0.85
tapMethod · 0.80
sliceMethod · 0.80
isArrayMethod · 0.80
setMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected