| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 21:30:17 +08:00
										 |  |  | const { compareChunksNatural } = require("../util/comparators"); | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | const { assignAscendingChunkIds } = require("./IdHelpers"); | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../Chunk")} Chunk */ | 
					
						
							|  |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | /** @typedef {import("../Module")} Module */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NaturalChunkIdsPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap("NaturalChunkIdsPlugin", compilation => { | 
					
						
							|  |  |  | 			compilation.hooks.chunkIds.tap("NaturalChunkIdsPlugin", chunks => { | 
					
						
							|  |  |  | 				const chunkGraph = compilation.chunkGraph; | 
					
						
							| 
									
										
										
										
											2018-10-17 21:30:17 +08:00
										 |  |  | 				const compareNatural = compareChunksNatural(chunkGraph); | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 				const chunksInNaturalOrder = Array.from(chunks).sort(compareNatural); | 
					
						
							|  |  |  | 				assignAscendingChunkIds(chunksInNaturalOrder, compilation); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = NaturalChunkIdsPlugin; |