* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 41 | * @returns {void} |
| 42 | */ |
| 43 | apply(compiler) { |
| 44 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 45 | const hashFunction = compilation.outputOptions.hashFunction; |
| 46 | compilation.hooks.chunkIds.tap(PLUGIN_NAME, (chunks) => { |
| 47 | const chunkGraph = compilation.chunkGraph; |
| 48 | const context = this.options.context |
| 49 | ? this.options.context |
| 50 | : compiler.context; |
| 51 | const delimiter = this.options.delimiter || "-"; |
| 52 | |
| 53 | const unnamedChunks = assignNames( |
| 54 | [...chunks].filter((chunk) => { |
| 55 | if (chunk.name) { |
| 56 | chunk.id = chunk.name; |
| 57 | chunk.ids = [chunk.name]; |
| 58 | } |
| 59 | return chunk.id === null; |
| 60 | }), |
| 61 | (chunk) => |
| 62 | getShortChunkName( |
| 63 | chunk, |
| 64 | chunkGraph, |
| 65 | context, |
| 66 | delimiter, |
| 67 | hashFunction, |
| 68 | compiler.root |
| 69 | ), |
| 70 | (chunk) => |
| 71 | getLongChunkName( |
| 72 | chunk, |
| 73 | chunkGraph, |
| 74 | context, |
| 75 | delimiter, |
| 76 | hashFunction, |
| 77 | compiler.root |
| 78 | ), |
| 79 | compareChunksNatural(chunkGraph), |
| 80 | getUsedChunkIds(compilation), |
| 81 | (chunk, name) => { |
| 82 | chunk.id = name; |
| 83 | chunk.ids = [name]; |
| 84 | } |
| 85 | ); |
| 86 | if (unnamedChunks.length > 0) { |
| 87 | assignAscendingChunkIds(unnamedChunks, compilation); |
| 88 | } |
| 89 | }); |
| 90 | }); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | module.exports = NamedChunkIdsPlugin; |
nothing calls this directly
no test coverage detected