* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 39 | * @returns {void} |
| 40 | */ |
| 41 | apply(compiler) { |
| 42 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 43 | compilation.hooks.chunkIds.tap(PLUGIN_NAME, (chunks) => { |
| 44 | const chunkGraph = compilation.chunkGraph; |
| 45 | const context = this.options.context |
| 46 | ? this.options.context |
| 47 | : compiler.context; |
| 48 | const maxLength = this.options.maxLength || 3; |
| 49 | |
| 50 | const compareNatural = compareChunksNatural(chunkGraph); |
| 51 | |
| 52 | const usedIds = getUsedChunkIds(compilation); |
| 53 | assignDeterministicIds( |
| 54 | [...chunks].filter((chunk) => chunk.id === null), |
| 55 | (chunk) => |
| 56 | getFullChunkName(chunk, chunkGraph, context, compiler.root), |
| 57 | compareNatural, |
| 58 | (chunk, id) => { |
| 59 | const size = usedIds.size; |
| 60 | usedIds.add(`${id}`); |
| 61 | if (size === usedIds.size) return false; |
| 62 | chunk.id = id; |
| 63 | chunk.ids = [id]; |
| 64 | return true; |
| 65 | }, |
| 66 | [10 ** maxLength], |
| 67 | 10, |
| 68 | usedIds.size |
| 69 | ); |
| 70 | }); |
| 71 | }); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | module.exports = DeterministicChunkIdsPlugin; |
nothing calls this directly
no test coverage detected