| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const DllModuleFactory = require("./DllModuleFactory"); | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | const DllEntryDependency = require("./dependencies/DllEntryDependency"); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | const EntryDependency = require("./dependencies/EntryDependency"); | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | /** @typedef {string[]} Entries */ | 
					
						
							|  |  |  | /** @typedef {{ name: string, filename: TODO }} Options */ | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | class DllEntryPlugin { | 
					
						
							| 
									
										
										
										
											2023-05-22 05:47:28 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} context context | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 	 * @param {Entries} entries entry names | 
					
						
							|  |  |  | 	 * @param {Options} options options | 
					
						
							| 
									
										
										
										
											2023-05-22 05:47:28 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	constructor(context, entries, options) { | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | 		this.context = context; | 
					
						
							|  |  |  | 		this.entries = entries; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		this.options = options; | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							|  |  |  | 			"DllEntryPlugin", | 
					
						
							|  |  |  | 			(compilation, { normalModuleFactory }) => { | 
					
						
							|  |  |  | 				const dllModuleFactory = new DllModuleFactory(); | 
					
						
							|  |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					DllEntryDependency, | 
					
						
							|  |  |  | 					dllModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyFactories.set( | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 					EntryDependency, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-12-06 22:01:25 +08:00
										 |  |  | 		compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			compilation.addEntry( | 
					
						
							|  |  |  | 				this.context, | 
					
						
							|  |  |  | 				new DllEntryDependency( | 
					
						
							|  |  |  | 					this.entries.map((e, idx) => { | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 						const dep = new EntryDependency(e); | 
					
						
							| 
									
										
										
										
											2018-06-25 16:43:59 +08:00
										 |  |  | 						dep.loc = { | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 							name: this.options.name, | 
					
						
							| 
									
										
										
										
											2018-06-25 16:43:59 +08:00
										 |  |  | 							index: idx | 
					
						
							|  |  |  | 						}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						return dep; | 
					
						
							|  |  |  | 					}), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 					this.options.name | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 				this.options, | 
					
						
							| 
									
										
										
										
											2023-06-17 02:49:43 +08:00
										 |  |  | 				error => { | 
					
						
							|  |  |  | 					if (error) return callback(error); | 
					
						
							|  |  |  | 					callback(); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2016-12-29 16:33:01 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = DllEntryPlugin; |