* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 40 | * @returns {void} |
| 41 | */ |
| 42 | apply(compiler) { |
| 43 | const { root } = compiler; |
| 44 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 45 | const hashFunction = compilation.outputOptions.hashFunction; |
| 46 | compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => { |
| 47 | const chunkGraph = compilation.chunkGraph; |
| 48 | const context = this.options.context |
| 49 | ? this.options.context |
| 50 | : compiler.context; |
| 51 | |
| 52 | const [usedIds, modules] = getUsedModuleIdsAndModules(compilation); |
| 53 | const unnamedModules = assignNames( |
| 54 | modules, |
| 55 | (m) => getShortModuleName(m, context, root), |
| 56 | (m, shortName) => |
| 57 | getLongModuleName(shortName, m, context, hashFunction, root), |
| 58 | compareModulesByIdentifier, |
| 59 | usedIds, |
| 60 | (m, name) => chunkGraph.setModuleId(m, name) |
| 61 | ); |
| 62 | if (unnamedModules.length > 0) { |
| 63 | assignAscendingModuleIds(usedIds, unnamedModules, compilation); |
| 64 | } |
| 65 | }); |
| 66 | }); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | module.exports = NamedModuleIdsPlugin; |
nothing calls this directly
no test coverage detected