| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							| 
									
										
										
										
											2017-08-09 08:50:10 +08:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:10 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */ | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | /** @typedef {import("./Compilation").EntryOptions} EntryOptions */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | class EntryOptionPlugin { | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance one is tapping into | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:10 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:00:32 +08:00
										 |  |  | 		compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => { | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 			if (typeof entry === "function") { | 
					
						
							|  |  |  | 				const DynamicEntryPlugin = require("./DynamicEntryPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 				new DynamicEntryPlugin(context, entry).apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				const EntryPlugin = require("./EntryPlugin"); | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 				for (const name of Object.keys(entry)) { | 
					
						
							|  |  |  | 					const desc = entry[name]; | 
					
						
							|  |  |  | 					const options = EntryOptionPlugin.entryDescriptionToOptions( | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 						compiler, | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 						name, | 
					
						
							|  |  |  | 						desc | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					for (const entry of desc.import) { | 
					
						
							|  |  |  | 						new EntryPlugin(context, entry, options).apply(compiler); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 13:02:10 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 	 * @param {string} name entry name | 
					
						
							|  |  |  | 	 * @param {EntryDescription} desc entry description | 
					
						
							|  |  |  | 	 * @returns {EntryOptions} options for the entry | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 	static entryDescriptionToOptions(compiler, name, desc) { | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 		/** @type {EntryOptions} */ | 
					
						
							|  |  |  | 		const options = { | 
					
						
							|  |  |  | 			name, | 
					
						
							|  |  |  | 			filename: desc.filename, | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 			dependOn: desc.dependOn, | 
					
						
							|  |  |  | 			library: desc.library | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 		if (desc.library) { | 
					
						
							|  |  |  | 			const EnableLibraryPlugin = require("./library/EnableLibraryPlugin"); | 
					
						
							|  |  |  | 			EnableLibraryPlugin.checkEnabled(compiler, desc.library.type); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 		return options; | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = EntryOptionPlugin; |