| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */ | 
					
						
							|  |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @type {WeakMap<Compiler, Set<LibraryType>>} */ | 
					
						
							|  |  |  | const enabledTypes = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {object} EnableLibraryPluginOptions | 
					
						
							| 
									
										
										
										
											2025-04-17 06:54:48 +08:00
										 |  |  |  * @property {() => void=} additionalApply function that runs when applying the current plugin. | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 08:59:10 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  |  * @returns {Set<LibraryType>} enabled types | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | const getEnabledTypes = compiler => { | 
					
						
							|  |  |  | 	let set = enabledTypes.get(compiler); | 
					
						
							|  |  |  | 	if (set === undefined) { | 
					
						
							|  |  |  | 		set = new Set(); | 
					
						
							|  |  |  | 		enabledTypes.set(compiler, set); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return set; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EnableLibraryPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {LibraryType} type library type that should be available | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  | 	 * @param {EnableLibraryPluginOptions} options options of EnableLibraryPlugin | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  | 	constructor(type, options = {}) { | 
					
						
							|  |  |  | 		/** @type {LibraryType} */ | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 		this.type = type; | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  | 		/** @type {EnableLibraryPluginOptions} */ | 
					
						
							|  |  |  | 		this.options = options; | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @param {LibraryType} type type of library | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static setEnabled(compiler, type) { | 
					
						
							|  |  |  | 		getEnabledTypes(compiler).add(type); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @param {LibraryType} type type of library | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static checkEnabled(compiler, type) { | 
					
						
							|  |  |  | 		if (!getEnabledTypes(compiler).has(type)) { | 
					
						
							|  |  |  | 			throw new Error( | 
					
						
							|  |  |  | 				`Library type "${type}" is not enabled. ` + | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					"EnableLibraryPlugin need to be used to enable this type of library. " + | 
					
						
							| 
									
										
										
										
											2024-10-14 11:02:08 +08:00
										 |  |  | 					'This usually happens through the "output.enabledLibraryTypes" option. ' + | 
					
						
							|  |  |  | 					'If you are using a function as entry which sets "library", you need to add all potential library types to "output.enabledLibraryTypes". ' + | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 					`These types are enabled: ${[...getEnabledTypes(compiler)].join(", ")}` | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  | 		const { type, options } = this; | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Only enable once
 | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 		const enabled = getEnabledTypes(compiler); | 
					
						
							|  |  |  | 		if (enabled.has(type)) return; | 
					
						
							|  |  |  | 		enabled.add(type); | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:39 +08:00
										 |  |  | 		if (typeof options.additionalApply === "function") { | 
					
						
							|  |  |  | 			options.additionalApply(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 		if (typeof type === "string") { | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 			const enableExportProperty = () => { | 
					
						
							|  |  |  | 				const ExportPropertyTemplatePlugin = require("./ExportPropertyLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 				new ExportPropertyTemplatePlugin({ | 
					
						
							|  |  |  | 					type, | 
					
						
							| 
									
										
										
										
											2024-07-09 20:02:25 +08:00
										 |  |  | 					nsObjectUsed: !["module", "modern-module"].includes(type), | 
					
						
							| 
									
										
										
										
											2025-04-06 22:53:09 +08:00
										 |  |  | 					runtimeExportsUsed: !["module", "modern-module"].includes(type), | 
					
						
							|  |  |  | 					renderStartupUsed: !["module", "modern-module"].includes(type) | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 				}).apply(compiler); | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 			switch (type) { | 
					
						
							|  |  |  | 				case "var": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: [], | 
					
						
							|  |  |  | 						declare: "var", | 
					
						
							|  |  |  | 						unnamed: "error" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-01-04 23:12:48 +08:00
										 |  |  | 				case "assign-properties": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2021-01-04 23:12:48 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 23:12:48 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: [], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "error", | 
					
						
							|  |  |  | 						named: "copy" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				case "assign": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: [], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "error" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "this": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: ["this"], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "copy" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "window": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: ["window"], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "copy" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "self": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: ["self"], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "copy" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "global": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: "global", | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "copy" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "commonjs": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: ["exports"], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "copy" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-12-19 03:17:50 +08:00
										 |  |  | 				case "commonjs-static": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2021-12-19 03:17:50 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-19 03:17:50 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: ["exports"], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "static" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				case "commonjs2": | 
					
						
							|  |  |  | 				case "commonjs-module": { | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AssignLibraryPlugin = require("./AssignLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AssignLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						prefix: ["module", "exports"], | 
					
						
							|  |  |  | 						declare: false, | 
					
						
							|  |  |  | 						unnamed: "assign" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "amd": | 
					
						
							|  |  |  | 				case "amd-require": { | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 					enableExportProperty(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const AmdLibraryPlugin = require("./AmdLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new AmdLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						requireAsWrapper: type === "amd-require" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "umd": | 
					
						
							|  |  |  | 				case "umd2": { | 
					
						
							| 
									
										
										
										
											2024-11-20 23:35:15 +08:00
										 |  |  | 					if (compiler.options.output.iife === false) { | 
					
						
							|  |  |  | 						compiler.options.output.iife = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						class WarnFalseIifeUmdPlugin { | 
					
						
							| 
									
										
										
										
											2025-03-07 21:12:22 +08:00
										 |  |  | 							/** | 
					
						
							|  |  |  | 							 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 							 */ | 
					
						
							| 
									
										
										
										
											2024-11-20 23:35:15 +08:00
										 |  |  | 							apply(compiler) { | 
					
						
							|  |  |  | 								compiler.hooks.thisCompilation.tap( | 
					
						
							|  |  |  | 									"WarnFalseIifeUmdPlugin", | 
					
						
							|  |  |  | 									compilation => { | 
					
						
							|  |  |  | 										const FalseIIFEUmdWarning = require("../FalseIIFEUmdWarning"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-20 23:35:15 +08:00
										 |  |  | 										compilation.warnings.push(new FalseIIFEUmdWarning()); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						new WarnFalseIifeUmdPlugin().apply(compiler); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 					enableExportProperty(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const UmdLibraryPlugin = require("./UmdLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new UmdLibraryPlugin({ | 
					
						
							|  |  |  | 						type, | 
					
						
							|  |  |  | 						optionalAmdExternalAsGlobal: type === "umd2" | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "system": { | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 					enableExportProperty(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const SystemLibraryPlugin = require("./SystemLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new SystemLibraryPlugin({ | 
					
						
							|  |  |  | 						type | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "jsonp": { | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 					enableExportProperty(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					const JsonpLibraryPlugin = require("./JsonpLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					new JsonpLibraryPlugin({ | 
					
						
							|  |  |  | 						type | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2025-04-06 22:53:09 +08:00
										 |  |  | 				case "module": | 
					
						
							|  |  |  | 				case "modern-module": { | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 					enableExportProperty(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 06:17:20 +08:00
										 |  |  | 					const ModuleLibraryPlugin = require("./ModuleLibraryPlugin"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 06:17:20 +08:00
										 |  |  | 					new ModuleLibraryPlugin({ | 
					
						
							|  |  |  | 						type | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2021-02-05 06:17:20 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 					throw new Error(`Unsupported library type ${type}.
 | 
					
						
							|  |  |  | Plugins which provide custom library types must call EnableLibraryPlugin.setEnabled(compiler, type) to disable this error.`);
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// TODO support plugin instances here
 | 
					
						
							|  |  |  | 			// apply them to the compiler
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = EnableLibraryPlugin; |