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

Method apply

lib/dependencies/LoaderPlugin.js:45–294  ·  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

43 * @returns {void}
44 */
45 apply(compiler) {
46 compiler.hooks.compilation.tap(
47 PLUGIN_NAME,
48 (compilation, { normalModuleFactory }) => {
49 compilation.dependencyFactories.set(
50 LoaderDependency,
51 normalModuleFactory
52 );
53 compilation.dependencyFactories.set(
54 LoaderImportDependency,
55 normalModuleFactory
56 );
57 }
58 );
59
60 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
61 const moduleGraph = compilation.moduleGraph;
62 NormalModule.getCompilationHooks(compilation).loader.tap(
63 PLUGIN_NAME,
64 (loaderContext) => {
65 loaderContext.loadModule = (request, callback) => {
66 const dep = new LoaderDependency(request);
67 dep.loc = {
68 name: request
69 };
70 const factory = compilation.dependencyFactories.get(
71 /** @type {DependencyConstructor} */
72 (dep.constructor)
73 );
74 if (factory === undefined) {
75 return callback(
76 new Error(
77 `No module factory available for dependency type: ${dep.constructor.name}`
78 )
79 );
80 }
81 const oldFactorizeQueueContext =
82 compilation.factorizeQueue.getContext();
83 compilation.factorizeQueue.setContext("load-module");
84 const oldAddModuleQueueContext =
85 compilation.addModuleQueue.getContext();
86 compilation.addModuleQueue.setContext("load-module");
87 compilation.buildQueue.increaseParallelism();
88 compilation.handleModuleCreation(
89 {
90 factory,
91 dependencies: [dep],
92 originModule:
93 /** @type {NormalModule} */
94 (loaderContext._module),
95 context: loaderContext.context,
96 recursive: false
97 },
98 (err) => {
99 compilation.factorizeQueue.setContext(oldFactorizeQueueContext);
100 compilation.addModuleQueue.setContext(oldAddModuleQueueContext);
101 compilation.buildQueue.decreaseParallelism();
102 if (err) {

Callers

nothing calls this directly

Calls 15

resolveFunction · 0.85
tapMethod · 0.80
setContextMethod · 0.80
increaseParallelismMethod · 0.80
handleModuleCreationMethod · 0.80
decreaseParallelismMethod · 0.80
getNumberOfErrorsMethod · 0.80
sourceMethod · 0.80
addDependencyMethod · 0.65
addContextDependencyMethod · 0.65
addMissingDependencyMethod · 0.65
addBuildDependencyMethod · 0.65

Tested by

no test coverage detected