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

Method apply

lib/dll/LibManifestPlugin.js:56–145  ·  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

54 * @returns {void}
55 */
56 apply(compiler) {
57 compiler.hooks.emit.tapAsync(
58 { name: PLUGIN_NAME, stage: 110 },
59 (compilation, callback) => {
60 const moduleGraph = compilation.moduleGraph;
61 // store used paths to detect issue and output an error. #18200
62 /** @type {Set<string>} */
63 const usedPaths = new Set();
64 asyncLib.each(
65 [...compilation.chunks],
66 (chunk, callback) => {
67 if (!chunk.canBeInitial()) {
68 callback();
69 return;
70 }
71 const chunkGraph = compilation.chunkGraph;
72 const targetPath = compilation.getPath(this.options.path, {
73 chunk
74 });
75 if (usedPaths.has(targetPath)) {
76 callback(new Error("each chunk must have a unique path"));
77 return;
78 }
79 usedPaths.add(targetPath);
80 const name =
81 this.options.name &&
82 compilation.getPath(this.options.name, {
83 chunk,
84 contentHashType: "javascript"
85 });
86 const content = Object.create(null);
87 for (const module of chunkGraph.getOrderedChunkModulesIterable(
88 chunk,
89 compareModulesById(chunkGraph)
90 )) {
91 if (
92 this.options.entryOnly &&
93 !someInIterable(
94 moduleGraph.getIncomingConnections(module),
95 (c) => c.dependency instanceof EntryDependency
96 )
97 ) {
98 continue;
99 }
100 const ident = module.libIdent({
101 context: this.options.context || compiler.context,
102 associatedObjectForCache: compiler.root
103 });
104 if (ident) {
105 const exportsInfo = moduleGraph.getExportsInfo(module);
106 const providedExports = exportsInfo.getProvidedExports();
107 /** @type {ManifestModuleData} */
108 const data = {
109 id: /** @type {ModuleId} */ (chunkGraph.getModuleId(module)),
110 buildMeta: /** @type {BuildMeta} */ (module.buildMeta),
111 exports: Array.isArray(providedExports)
112 ? providedExports
113 : undefined

Callers

nothing calls this directly

Calls 15

compareModulesByIdFunction · 0.85
someInIterableFunction · 0.85
mkdirpFunction · 0.85
dirnameFunction · 0.85
canBeInitialMethod · 0.80
getPathMethod · 0.80
getExportsInfoMethod · 0.80
getModuleIdMethod · 0.80
isArrayMethod · 0.80
callbackFunction · 0.50

Tested by

no test coverage detected