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

Method apply

lib/ModuleInfoHeaderPlugin.js:172–306  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

170 * @returns {void}
171 */
172 apply(compiler) {
173 const { _verbose: verbose } = this;
174 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
175 const javascriptHooks =
176 JavascriptModulesPlugin.getCompilationHooks(compilation);
177 javascriptHooks.renderModulePackage.tap(
178 PLUGIN_NAME,
179 (
180 moduleSource,
181 module,
182 { chunk, chunkGraph, moduleGraph, runtimeTemplate }
183 ) => {
184 const { requestShortener } = runtimeTemplate;
185 /** @type {undefined | CacheEntry} */
186 let cacheEntry;
187 let cache = caches.get(requestShortener);
188 if (cache === undefined) {
189 caches.set(requestShortener, (cache = new WeakMap()));
190 cache.set(
191 module,
192 (cacheEntry = { header: undefined, full: new WeakMap() })
193 );
194 } else {
195 cacheEntry = cache.get(module);
196 if (cacheEntry === undefined) {
197 cache.set(
198 module,
199 (cacheEntry = { header: undefined, full: new WeakMap() })
200 );
201 } else if (!verbose) {
202 const cachedSource = cacheEntry.full.get(moduleSource);
203 if (cachedSource !== undefined) return cachedSource;
204 }
205 }
206 const source = new ConcatSource();
207 let header = cacheEntry.header;
208 if (header === undefined) {
209 header = this.generateHeader(module, requestShortener);
210 cacheEntry.header = header;
211 }
212 source.add(header);
213 if (verbose) {
214 const exportsType = /** @type {BuildMeta} */ (module.buildMeta)
215 .exportsType;
216 source.add(
217 `${Template.toComment(
218 exportsType
219 ? `${exportsType} exports`
220 : "unknown exports (runtime-defined)"
221 )}\n`
222 );
223 if (exportsType) {
224 const exportsInfo = moduleGraph.getExportsInfo(module);
225 printExportsInfoToSource(
226 source,
227 "",
228 exportsInfo,
229 moduleGraph,

Callers

nothing calls this directly

Calls 13

generateHeaderMethod · 0.95
printExportsInfoToSourceFunction · 0.85
tapMethod · 0.80
toCommentMethod · 0.80
getExportsInfoMethod · 0.80
joinIterableWithCommaFunction · 0.70
getCompilationHooksMethod · 0.45
getMethod · 0.45
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected