| 
									
										
										
										
											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
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | const DllEntryPlugin = require("./DllEntryPlugin"); | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const LibManifestPlugin = require("./LibManifestPlugin"); | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | const createSchemaValidation = require("./util/create-schema-validation"); | 
					
						
							| 
									
										
										
										
											2017-10-28 05:23:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | /** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | /** @typedef {import("./DllEntryPlugin").Entries} Entries */ | 
					
						
							|  |  |  | /** @typedef {import("./DllEntryPlugin").Options} Options */ | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | const validate = createSchemaValidation( | 
					
						
							|  |  |  | 	require("../schemas/plugins/DllPlugin.check.js"), | 
					
						
							|  |  |  | 	() => require("../schemas/plugins/DllPlugin.json"), | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		name: "Dll Plugin", | 
					
						
							|  |  |  | 		baseDataPath: "options" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | class DllPlugin { | 
					
						
							| 
									
										
										
										
											2018-09-20 16:13:55 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {DllPluginOptions} options options object | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 	constructor(options) { | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | 		validate(options); | 
					
						
							| 
									
										
										
										
											2020-01-03 00:46:21 +08:00
										 |  |  | 		this.options = { | 
					
						
							|  |  |  | 			...options, | 
					
						
							|  |  |  | 			entryOnly: options.entryOnly !== false | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2017-12-06 22:01:25 +08:00
										 |  |  | 		compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => { | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			if (typeof entry !== "function") { | 
					
						
							|  |  |  | 				for (const name of Object.keys(entry)) { | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 					/** @type {Options} */ | 
					
						
							|  |  |  | 					const options = { name, filename: entry.filename }; | 
					
						
							|  |  |  | 					new DllEntryPlugin( | 
					
						
							|  |  |  | 						context, | 
					
						
							|  |  |  | 						/** @type {Entries} */ (entry[name].import), | 
					
						
							|  |  |  | 						options | 
					
						
							|  |  |  | 					).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 				throw new Error( | 
					
						
							|  |  |  | 					"DllPlugin doesn't support dynamic entry (function) yet" | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new LibManifestPlugin(this.options).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-19 03:13:10 +08:00
										 |  |  | 		if (!this.options.entryOnly) { | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 			new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-19 03:13:10 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-05 13:59:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | module.exports = DllPlugin; |