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

Method apply

lib/library/AbstractLibraryPlugin.js:68–227  ·  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

66 * @returns {void}
67 */
68 apply(compiler) {
69 const { _pluginName } = this;
70 compiler.hooks.thisCompilation.tap(_pluginName, (compilation) => {
71 compilation.hooks.finishModules.tap(
72 { name: _pluginName, stage: 10 },
73 () => {
74 for (const [
75 name,
76 {
77 dependencies: deps,
78 options: { library }
79 }
80 ] of compilation.entries) {
81 const options = this._parseOptionsCached(
82 library !== undefined
83 ? library
84 : compilation.outputOptions.library
85 );
86 if (options !== false) {
87 const dep = deps[deps.length - 1];
88 if (dep) {
89 const module = compilation.moduleGraph.getModule(dep);
90 if (module) {
91 this.finishEntryModule(module, name, {
92 options,
93 compilation,
94 chunkGraph: compilation.chunkGraph
95 });
96 }
97 }
98 }
99 }
100 }
101 );
102
103 /**
104 * Gets options for chunk.
105 * @param {Chunk} chunk chunk
106 * @returns {T | false} options for the chunk
107 */
108 const getOptionsForChunk = (chunk) => {
109 if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0) {
110 return false;
111 }
112 const options = chunk.getEntryOptions();
113 const library = options && options.library;
114 return this._parseOptionsCached(
115 library !== undefined ? library : compilation.outputOptions.library
116 );
117 };
118
119 if (
120 this.render !== AbstractLibraryPlugin.prototype.render ||
121 this.runtimeRequirements !==
122 AbstractLibraryPlugin.prototype.runtimeRequirements
123 ) {
124 compilation.hooks.additionalChunkRuntimeRequirements.tap(
125 _pluginName,

Callers

nothing calls this directly

Calls 12

_parseOptionsCachedMethod · 0.95
finishEntryModuleMethod · 0.95
runtimeRequirementsMethod · 0.95
renderMethod · 0.95
embedInRuntimeBailoutMethod · 0.95
strictRuntimeBailoutMethod · 0.95
renderModuleContentMethod · 0.95
renderStartupMethod · 0.95
chunkHashMethod · 0.95
tapMethod · 0.80
getModuleMethod · 0.45
getCompilationHooksMethod · 0.45

Tested by

no test coverage detected