| 
									
										
										
										
											2017-03-23 20:39:33 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 20:39:33 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NamedChunksPlugin { | 
					
						
							|  |  |  | 	static defaultNameResolver(chunk) { | 
					
						
							|  |  |  | 		return chunk.name || null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	constructor(nameResolver) { | 
					
						
							|  |  |  | 		this.nameResolver = nameResolver || NamedChunksPlugin.defaultNameResolver; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap("NamedChunksPlugin", compilation => { | 
					
						
							|  |  |  | 			compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", chunks => { | 
					
						
							|  |  |  | 				for (const chunk of chunks) { | 
					
						
							|  |  |  | 					if (chunk.id === null) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 						chunk.id = this.nameResolver(chunk, { | 
					
						
							|  |  |  | 							moduleGraph: compilation.moduleGraph, | 
					
						
							|  |  |  | 							chunkGraph: compilation.chunkGraph | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-03-23 20:39:33 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-23 20:39:33 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = NamedChunksPlugin; |