| 
									
										
										
										
											2013-01-31 01:49:25 +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-01-04 12:18:43 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | const EntryDependency = require("./dependencies/EntryDependency"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | class EntryPlugin { | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * An entry plugin which will handle | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	 * creation of the EntryDependency | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {string} context context path | 
					
						
							|  |  |  | 	 * @param {string} entry entry path | 
					
						
							| 
									
										
										
										
											2021-04-23 03:43:43 +08:00
										 |  |  | 	 * @param {EntryOptions | string=} options entry options (passing a string is deprecated) | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 	constructor(context, entry, options) { | 
					
						
							| 
									
										
										
										
											2017-01-04 12:18:43 +08:00
										 |  |  | 		this.context = context; | 
					
						
							|  |  |  | 		this.entry = entry; | 
					
						
							| 
									
										
										
										
											2020-05-27 00:08:16 +08:00
										 |  |  | 		this.options = options || ""; | 
					
						
							| 
									
										
										
										
											2017-01-04 12:18:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-04 12:18:43 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			"EntryPlugin", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			(compilation, { normalModuleFactory }) => { | 
					
						
							|  |  |  | 				compilation.dependencyFactories.set( | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 					EntryDependency, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-04 12:18:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-26 21:53:56 +08:00
										 |  |  | 		const { entry, options, context } = this; | 
					
						
							|  |  |  | 		const dep = EntryPlugin.createDependency(entry, options); | 
					
						
							| 
									
										
										
										
											2017-12-08 15:00:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-26 21:53:56 +08:00
										 |  |  | 		compiler.hooks.make.tapAsync("EntryPlugin", (compilation, callback) => { | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 			compilation.addEntry(context, dep, options, err => { | 
					
						
							| 
									
										
										
										
											2018-12-18 04:35:39 +08:00
										 |  |  | 				callback(err); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-04 12:18:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-09 15:31:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-10 23:18:45 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} entry entry request | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 	 * @param {EntryOptions | string} options entry options (passing string is deprecated) | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	 * @returns {EntryDependency} the dependency | 
					
						
							| 
									
										
										
										
											2018-07-10 23:18:45 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 	static createDependency(entry, options) { | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		const dep = new EntryDependency(entry); | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 		// TODO webpack 6 remove string option
 | 
					
						
							|  |  |  | 		dep.loc = { name: typeof options === "object" ? options.name : options }; | 
					
						
							| 
									
										
										
										
											2017-01-09 15:31:49 +08:00
										 |  |  | 		return dep; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | module.exports = EntryPlugin; |