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

Method apply

lib/ids/HashedModuleIdsPlugin.js:38–81  ·  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

36 * @returns {void}
37 */
38 apply(compiler) {
39 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
40 compiler.validate(
41 () => require("../../schemas/plugins/ids/HashedModuleIdsPlugin.json"),
42 this.options,
43 {
44 name: "Hashed Module Ids Plugin",
45 baseDataPath: "options"
46 },
47 (options) =>
48 require("../../schemas/plugins/ids/HashedModuleIdsPlugin.check")(
49 options
50 )
51 );
52 });
53 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
54 compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
55 const chunkGraph = compilation.chunkGraph;
56 const context = this.options.context
57 ? this.options.context
58 : compiler.context;
59
60 const [usedIds, modules] = getUsedModuleIdsAndModules(compilation);
61 const modulesInNaturalOrder = modules.sort(
62 compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
63 );
64 for (const module of modulesInNaturalOrder) {
65 const ident = getFullModuleName(module, context, compiler.root);
66 const hash = createHash(
67 this.options.hashFunction || DEFAULTS.HASH_FUNCTION
68 );
69 hash.update(ident || "");
70 const hashId = hash.digest(this.options.hashDigest || "base64");
71 let len = this.options.hashDigestLength || 4;
72 while (usedIds.has(hashId.slice(0, len))) {
73 /** @type {number} */ (len)++;
74 }
75 const moduleId = hashId.slice(0, len);
76 chunkGraph.setModuleId(module, moduleId);
77 usedIds.add(moduleId);
78 }
79 });
80 });
81 }
82}
83
84module.exports = HashedModuleIdsPlugin;

Callers

nothing calls this directly

Calls 14

getFullModuleNameFunction · 0.85
createHashFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
sortMethod · 0.80
sliceMethod · 0.80
setModuleIdMethod · 0.80
requireFunction · 0.50
updateMethod · 0.45
digestMethod · 0.45

Tested by

no test coverage detected