| 
									
										
										
										
											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-02-21 21:49:15 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const OptionsApply = require("./OptionsApply"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 21:07:15 +08:00
										 |  |  | const AssetModulesPlugin = require("./asset/AssetModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:46:57 +08:00
										 |  |  | const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); | 
					
						
							|  |  |  | const JsonModulesPlugin = require("./json/JsonModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2017-11-10 18:02:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | const ChunkPrefetchPreloadPlugin = require("./prefetch/ChunkPrefetchPreloadPlugin"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const EntryOptionPlugin = require("./EntryOptionPlugin"); | 
					
						
							|  |  |  | const RecordIdsPlugin = require("./RecordIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | const RuntimePlugin = require("./RuntimePlugin"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const APIPlugin = require("./APIPlugin"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const CompatibilityPlugin = require("./CompatibilityPlugin"); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const ConstPlugin = require("./ConstPlugin"); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | const ExportsInfoApiPlugin = require("./ExportsInfoApiPlugin"); | 
					
						
							| 
									
										
										
										
											2020-04-05 17:30:57 +08:00
										 |  |  | const WebpackIsIncludedPlugin = require("./WebpackIsIncludedPlugin"); | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const TemplatedPathPlugin = require("./TemplatedPathPlugin"); | 
					
						
							|  |  |  | const UseStrictPlugin = require("./UseStrictPlugin"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const WarnCaseSensitiveModulesPlugin = require("./WarnCaseSensitiveModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | const DataUriPlugin = require("./schemes/DataUriPlugin"); | 
					
						
							|  |  |  | const FileUriPlugin = require("./schemes/FileUriPlugin"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 13:22:44 +08:00
										 |  |  | const ResolverCachePlugin = require("./cache/ResolverCachePlugin"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const CommonJsPlugin = require("./dependencies/CommonJsPlugin"); | 
					
						
							|  |  |  | const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | const ImportMetaPlugin = require("./dependencies/ImportMetaPlugin"); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const ImportPlugin = require("./dependencies/ImportPlugin"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const LoaderPlugin = require("./dependencies/LoaderPlugin"); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | const RequireContextPlugin = require("./dependencies/RequireContextPlugin"); | 
					
						
							|  |  |  | const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin"); | 
					
						
							|  |  |  | const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const SystemPlugin = require("./dependencies/SystemPlugin"); | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | const URLPlugin = require("./dependencies/URLPlugin"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 02:29:53 +08:00
										 |  |  | const InferAsyncModulesPlugin = require("./async-modules/InferAsyncModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-16 21:40:14 +08:00
										 |  |  | const FlagUsingEvalPlugin = require("./FlagUsingEvalPlugin"); | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | const DefaultStatsFactoryPlugin = require("./stats/DefaultStatsFactoryPlugin"); | 
					
						
							|  |  |  | const DefaultStatsPresetPlugin = require("./stats/DefaultStatsPresetPlugin"); | 
					
						
							|  |  |  | const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 04:17:14 +08:00
										 |  |  | const { cleverMerge } = require("./util/cleverMerge"); | 
					
						
							| 
									
										
										
										
											2019-05-13 21:16:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | class WebpackOptionsApply extends OptionsApply { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-20 13:39:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {WebpackOptions} options options object | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler compiler object | 
					
						
							|  |  |  | 	 * @returns {WebpackOptions} options object | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 	process(options, compiler) { | 
					
						
							|  |  |  | 		compiler.outputPath = options.output.path; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		compiler.recordsInputPath = options.recordsInputPath || null; | 
					
						
							|  |  |  | 		compiler.recordsOutputPath = options.recordsOutputPath || null; | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		compiler.name = options.name; | 
					
						
							| 
									
										
										
										
											2016-12-03 04:49:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 		if (options.externalsPresets.node) { | 
					
						
							|  |  |  | 			const NodeTargetPlugin = require("./node/NodeTargetPlugin"); | 
					
						
							|  |  |  | 			new NodeTargetPlugin().apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (options.externalsPresets.electronMain) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 			const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin"); | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 			new ElectronTargetPlugin("main").apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.externalsPresets.electronPreload) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 			const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin"); | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 			new ElectronTargetPlugin("preload").apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (options.externalsPresets.electronRenderer) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 			const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin"); | 
					
						
							|  |  |  | 			new ElectronTargetPlugin("renderer").apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if ( | 
					
						
							|  |  |  | 			options.externalsPresets.electron && | 
					
						
							|  |  |  | 			!options.externalsPresets.electronMain && | 
					
						
							|  |  |  | 			!options.externalsPresets.electronPreload && | 
					
						
							|  |  |  | 			!options.externalsPresets.electronRenderer | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 			const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin"); | 
					
						
							|  |  |  | 			new ElectronTargetPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 		if (options.externalsPresets.nwjs) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 			const ExternalsPlugin = require("./ExternalsPlugin"); | 
					
						
							|  |  |  | 			new ExternalsPlugin("commonjs", "nw.gui").apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (options.externalsPresets.webAsync) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 			const ExternalsPlugin = require("./ExternalsPlugin"); | 
					
						
							|  |  |  | 			new ExternalsPlugin("import", /^(https?:\/\/|std:)/).apply(compiler); | 
					
						
							|  |  |  | 		} else if (options.externalsPresets.web) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2020-09-09 21:16:53 +08:00
										 |  |  | 			const ExternalsPlugin = require("./ExternalsPlugin"); | 
					
						
							|  |  |  | 			new ExternalsPlugin("module", /^(https?:\/\/|std:)/).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 		new ChunkPrefetchPreloadPlugin().apply(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (typeof options.output.chunkFormat === "string") { | 
					
						
							|  |  |  | 			switch (options.output.chunkFormat) { | 
					
						
							|  |  |  | 				case "array-push": { | 
					
						
							|  |  |  | 					const ArrayPushCallbackChunkFormatPlugin = require("./javascript/ArrayPushCallbackChunkFormatPlugin"); | 
					
						
							|  |  |  | 					new ArrayPushCallbackChunkFormatPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 				case "commonjs": { | 
					
						
							|  |  |  | 					const CommonJsChunkFormatPlugin = require("./javascript/CommonJsChunkFormatPlugin"); | 
					
						
							|  |  |  | 					new CommonJsChunkFormatPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 				case "module": | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							| 
									
										
										
										
											2020-10-24 02:19:18 +08:00
										 |  |  | 						"EcmaScript Module Chunk Format is not implemented yet" | 
					
						
							| 
									
										
										
										
											2020-09-10 16:42:29 +08:00
										 |  |  | 					); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						"Unsupported chunk format '" + options.output.chunkFormat + "'." | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (options.output.enabledChunkLoadingTypes.length > 0) { | 
					
						
							|  |  |  | 			for (const type of options.output.enabledChunkLoadingTypes) { | 
					
						
							|  |  |  | 				const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin"); | 
					
						
							|  |  |  | 				new EnableChunkLoadingPlugin(type).apply(compiler); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 15:23:01 +08:00
										 |  |  | 		if (options.output.enabledWasmLoadingTypes.length > 0) { | 
					
						
							|  |  |  | 			for (const type of options.output.enabledWasmLoadingTypes) { | 
					
						
							|  |  |  | 				const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin"); | 
					
						
							|  |  |  | 				new EnableWasmLoadingPlugin(type).apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-04-09 15:12:04 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-03 04:49:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 		if (options.output.enabledLibraryTypes.length > 0) { | 
					
						
							|  |  |  | 			for (const type of options.output.enabledLibraryTypes) { | 
					
						
							|  |  |  | 				const EnableLibraryPlugin = require("./library/EnableLibraryPlugin"); | 
					
						
							|  |  |  | 				new EnableLibraryPlugin(type).apply(compiler); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (options.externals) { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 			//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 			const ExternalsPlugin = require("./ExternalsPlugin"); | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			new ExternalsPlugin(options.externalsType, options.externals).apply( | 
					
						
							|  |  |  | 				compiler | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-18 06:48:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 		if (options.output.pathinfo) { | 
					
						
							| 
									
										
										
										
											2019-10-09 19:44:39 +08:00
										 |  |  | 			const ModuleInfoHeaderPlugin = require("./ModuleInfoHeaderPlugin"); | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 			new ModuleInfoHeaderPlugin(options.output.pathinfo !== true).apply( | 
					
						
							|  |  |  | 				compiler | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-30 23:33:30 +08:00
										 |  |  | 		if (options.output.clean) { | 
					
						
							|  |  |  | 			const CleanPlugin = require("./CleanPlugin"); | 
					
						
							| 
									
										
										
										
											2020-10-07 20:30:14 +08:00
										 |  |  | 			new CleanPlugin( | 
					
						
							|  |  |  | 				options.output.clean === true ? {} : options.output.clean | 
					
						
							|  |  |  | 			).apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-09-30 23:33:30 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-18 21:09:34 +08:00
										 |  |  | 		if (options.devtool) { | 
					
						
							|  |  |  | 			if (options.devtool.includes("source-map")) { | 
					
						
							|  |  |  | 				const hidden = options.devtool.includes("hidden"); | 
					
						
							|  |  |  | 				const inline = options.devtool.includes("inline"); | 
					
						
							|  |  |  | 				const evalWrapped = options.devtool.includes("eval"); | 
					
						
							|  |  |  | 				const cheap = options.devtool.includes("cheap"); | 
					
						
							|  |  |  | 				const moduleMaps = options.devtool.includes("module"); | 
					
						
							|  |  |  | 				const noSources = options.devtool.includes("nosources"); | 
					
						
							|  |  |  | 				const Plugin = evalWrapped | 
					
						
							|  |  |  | 					? require("./EvalSourceMapDevToolPlugin") | 
					
						
							|  |  |  | 					: require("./SourceMapDevToolPlugin"); | 
					
						
							|  |  |  | 				new Plugin({ | 
					
						
							|  |  |  | 					filename: inline ? null : options.output.sourceMapFilename, | 
					
						
							|  |  |  | 					moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate, | 
					
						
							|  |  |  | 					fallbackModuleFilenameTemplate: | 
					
						
							|  |  |  | 						options.output.devtoolFallbackModuleFilenameTemplate, | 
					
						
							|  |  |  | 					append: hidden ? false : undefined, | 
					
						
							|  |  |  | 					module: moduleMaps ? true : cheap ? false : true, | 
					
						
							|  |  |  | 					columns: cheap ? false : true, | 
					
						
							|  |  |  | 					noSources: noSources, | 
					
						
							|  |  |  | 					namespace: options.output.devtoolNamespace | 
					
						
							|  |  |  | 				}).apply(compiler); | 
					
						
							|  |  |  | 			} else if (options.devtool.includes("eval")) { | 
					
						
							|  |  |  | 				const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin"); | 
					
						
							|  |  |  | 				new EvalDevToolModulePlugin({ | 
					
						
							|  |  |  | 					moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate, | 
					
						
							|  |  |  | 					namespace: options.output.devtoolNamespace | 
					
						
							|  |  |  | 				}).apply(compiler); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 17:53:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new JavascriptModulesPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new JsonModulesPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-09-02 21:07:15 +08:00
										 |  |  | 		new AssetModulesPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-07-16 19:16:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		if (!options.experiments.outputModule) { | 
					
						
							|  |  |  | 			if (options.output.module) { | 
					
						
							|  |  |  | 				throw new Error( | 
					
						
							| 
									
										
										
										
											2019-11-04 15:35:59 +08:00
										 |  |  | 					"'output.module: true' is only allowed when 'experiments.outputModule' is enabled" | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 			if (options.output.enabledLibraryTypes.includes("module")) { | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 				throw new Error( | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 					"library type \"module\" is only allowed when 'experiments.outputModule' is enabled" | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			if (options.externalsType === "module") { | 
					
						
							|  |  |  | 				throw new Error( | 
					
						
							|  |  |  | 					"'externalsType: \"module\"' is only allowed when 'experiments.outputModule' is enabled" | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 		if (options.experiments.syncWebAssembly) { | 
					
						
							| 
									
										
										
										
											2020-09-09 15:23:01 +08:00
										 |  |  | 			const WebAssemblyModulesPlugin = require("./wasm-sync/WebAssemblyModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 			new WebAssemblyModulesPlugin({ | 
					
						
							|  |  |  | 				mangleImports: options.optimization.mangleWasmImports | 
					
						
							|  |  |  | 			}).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (options.experiments.asyncWebAssembly) { | 
					
						
							|  |  |  | 			const AsyncWebAssemblyModulesPlugin = require("./wasm-async/AsyncWebAssemblyModulesPlugin"); | 
					
						
							|  |  |  | 			new AsyncWebAssemblyModulesPlugin({ | 
					
						
							|  |  |  | 				mangleImports: options.optimization.mangleWasmImports | 
					
						
							|  |  |  | 			}).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 		if (options.experiments.lazyCompilation) { | 
					
						
							|  |  |  | 			const LazyCompilationPlugin = require("./hmr/LazyCompilationPlugin"); | 
					
						
							| 
									
										
										
										
											2021-02-01 22:52:47 +08:00
										 |  |  | 			const lazyOptions = | 
					
						
							|  |  |  | 				typeof options.experiments.lazyCompilation === "object" | 
					
						
							|  |  |  | 					? options.experiments.lazyCompilation | 
					
						
							|  |  |  | 					: null; | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 			new LazyCompilationPlugin({ | 
					
						
							|  |  |  | 				backend: | 
					
						
							| 
									
										
										
										
											2021-02-01 22:52:47 +08:00
										 |  |  | 					(lazyOptions && lazyOptions.backend) || | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 					require("./hmr/lazyCompilationBackend"), | 
					
						
							|  |  |  | 				client: | 
					
						
							| 
									
										
										
										
											2021-02-01 22:52:47 +08:00
										 |  |  | 					(lazyOptions && lazyOptions.client) || | 
					
						
							| 
									
										
										
										
											2021-01-22 17:24:25 +08:00
										 |  |  | 					require.resolve( | 
					
						
							|  |  |  | 						`../hot/lazy-compilation-${ | 
					
						
							|  |  |  | 							options.externalsPresets.node ? "node" : "web" | 
					
						
							|  |  |  | 						}.js`
 | 
					
						
							|  |  |  | 					), | 
					
						
							| 
									
										
										
										
											2021-02-01 22:52:47 +08:00
										 |  |  | 				entries: !lazyOptions || lazyOptions.entries !== false, | 
					
						
							|  |  |  | 				imports: !lazyOptions || lazyOptions.imports !== false, | 
					
						
							| 
									
										
										
										
											2021-02-02 00:12:20 +08:00
										 |  |  | 				test: lazyOptions && lazyOptions.test | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 			}).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new EntryOptionPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		compiler.hooks.entryOption.call(options.context, options.entry); | 
					
						
							| 
									
										
										
										
											2013-06-19 17:53:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 		new RuntimePlugin().apply(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 06:47:08 +08:00
										 |  |  | 		new InferAsyncModulesPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 		new DataUriPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new FileUriPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new CompatibilityPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 		new HarmonyModulesPlugin({ | 
					
						
							| 
									
										
										
										
											2020-08-04 06:47:08 +08:00
										 |  |  | 			topLevelAwait: options.experiments.topLevelAwait | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 		}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-03-11 00:13:53 +08:00
										 |  |  | 		if (options.amd !== false) { | 
					
						
							| 
									
										
										
										
											2019-03-10 23:31:35 +08:00
										 |  |  | 			const AMDPlugin = require("./dependencies/AMDPlugin"); | 
					
						
							|  |  |  | 			const RequireJsStuffPlugin = require("./RequireJsStuffPlugin"); | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 			new AMDPlugin(options.amd || {}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-03-10 23:31:35 +08:00
										 |  |  | 			new RequireJsStuffPlugin().apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 		new CommonJsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new LoaderPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-04-24 10:40:51 +08:00
										 |  |  | 		if (options.node !== false) { | 
					
						
							|  |  |  | 			const NodeStuffPlugin = require("./NodeStuffPlugin"); | 
					
						
							|  |  |  | 			new NodeStuffPlugin(options.node).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new APIPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:59:37 +08:00
										 |  |  | 		new ExportsInfoApiPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-04-05 17:30:57 +08:00
										 |  |  | 		new WebpackIsIncludedPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new ConstPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new UseStrictPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new RequireIncludePlugin().apply(compiler); | 
					
						
							|  |  |  | 		new RequireEnsurePlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-07-14 18:02:32 +08:00
										 |  |  | 		new RequireContextPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 		new ImportPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new SystemPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | 		new ImportMetaPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | 		new URLPlugin().apply(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (options.output.workerChunkLoading) { | 
					
						
							|  |  |  | 			const WorkerPlugin = require("./dependencies/WorkerPlugin"); | 
					
						
							|  |  |  | 			new WorkerPlugin(options.output.workerChunkLoading).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		new DefaultStatsFactoryPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new DefaultStatsPresetPlugin().apply(compiler); | 
					
						
							|  |  |  | 		new DefaultStatsPrinterPlugin().apply(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-16 21:40:14 +08:00
										 |  |  | 		new FlagUsingEvalPlugin().apply(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (typeof options.mode !== "string") { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:26:05 +08:00
										 |  |  | 			const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new WarnNoModeSetPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 05:26:05 +08:00
										 |  |  | 		const EnsureChunkConditionsPlugin = require("./optimize/EnsureChunkConditionsPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new EnsureChunkConditionsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (options.optimization.removeAvailableModules) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:26:05 +08:00
										 |  |  | 			const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new RemoveParentModulesPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.removeEmptyChunks) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:26:05 +08:00
										 |  |  | 			const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new RemoveEmptyChunksPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.mergeDuplicateChunks) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new MergeDuplicateChunksPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.flagIncludedChunks) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new FlagIncludedChunksPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.sideEffects) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const SideEffectsFlagPlugin = require("./optimize/SideEffectsFlagPlugin"); | 
					
						
							| 
									
										
										
										
											2020-10-26 22:32:34 +08:00
										 |  |  | 			new SideEffectsFlagPlugin( | 
					
						
							|  |  |  | 				options.optimization.sideEffects === true | 
					
						
							|  |  |  | 			).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.providedExports) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new FlagDependencyExportsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.usedExports) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 			new FlagDependencyUsagePlugin( | 
					
						
							|  |  |  | 				options.optimization.usedExports === "global" | 
					
						
							|  |  |  | 			).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-03 20:11:50 +08:00
										 |  |  | 		if (options.optimization.innerGraph) { | 
					
						
							|  |  |  | 			const InnerGraphPlugin = require("./optimize/InnerGraphPlugin"); | 
					
						
							|  |  |  | 			new InnerGraphPlugin().apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-01-28 17:40:32 +08:00
										 |  |  | 		if (options.optimization.mangleExports) { | 
					
						
							| 
									
										
										
										
											2019-05-10 03:34:28 +08:00
										 |  |  | 			const MangleExportsPlugin = require("./optimize/MangleExportsPlugin"); | 
					
						
							| 
									
										
										
										
											2020-07-31 18:13:30 +08:00
										 |  |  | 			new MangleExportsPlugin( | 
					
						
							|  |  |  | 				options.optimization.mangleExports !== "size" | 
					
						
							|  |  |  | 			).apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-01-28 17:40:32 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (options.optimization.concatenateModules) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const ModuleConcatenationPlugin = require("./optimize/ModuleConcatenationPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new ModuleConcatenationPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.splitChunks) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const SplitChunksPlugin = require("./optimize/SplitChunksPlugin"); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (options.optimization.runtimeChunk) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin"); | 
					
						
							| 
									
										
										
										
											2018-01-26 01:52:36 +08:00
										 |  |  | 			new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-07-17 21:39:16 +08:00
										 |  |  | 		if (!options.optimization.emitOnErrors) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new NoEmitOnErrorsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 		if (options.optimization.realContentHash) { | 
					
						
							|  |  |  | 			const RealContentHashPlugin = require("./optimize/RealContentHashPlugin"); | 
					
						
							|  |  |  | 			new RealContentHashPlugin({ | 
					
						
							|  |  |  | 				hashFunction: options.output.hashFunction, | 
					
						
							|  |  |  | 				hashDigest: options.output.hashDigest | 
					
						
							|  |  |  | 			}).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-05 02:14:08 +08:00
										 |  |  | 		if (options.optimization.checkWasmTypes) { | 
					
						
							| 
									
										
										
										
											2020-09-09 15:23:01 +08:00
										 |  |  | 			const WasmFinalizeExportsPlugin = require("./wasm-sync/WasmFinalizeExportsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-06-05 02:14:08 +08:00
										 |  |  | 			new WasmFinalizeExportsPlugin().apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-15 03:48:49 +08:00
										 |  |  | 		const moduleIds = options.optimization.moduleIds; | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 		if (moduleIds) { | 
					
						
							|  |  |  | 			switch (moduleIds) { | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				case "natural": { | 
					
						
							|  |  |  | 					const NaturalModuleIdsPlugin = require("./ids/NaturalModuleIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-07-23 02:25:56 +08:00
										 |  |  | 					new NaturalModuleIdsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "named": { | 
					
						
							|  |  |  | 					const NamedModuleIdsPlugin = require("./ids/NamedModuleIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-04 01:23:27 +08:00
										 |  |  | 					new NamedModuleIdsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "hashed": { | 
					
						
							|  |  |  | 					const WarnDeprecatedOptionPlugin = require("./WarnDeprecatedOptionPlugin"); | 
					
						
							|  |  |  | 					const HashedModuleIdsPlugin = require("./ids/HashedModuleIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-10-12 22:53:14 +08:00
										 |  |  | 					new WarnDeprecatedOptionPlugin( | 
					
						
							|  |  |  | 						"optimization.moduleIds", | 
					
						
							|  |  |  | 						"hashed", | 
					
						
							|  |  |  | 						"deterministic" | 
					
						
							|  |  |  | 					).apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 					new HashedModuleIdsPlugin().apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "deterministic": { | 
					
						
							|  |  |  | 					const DeterministicModuleIdsPlugin = require("./ids/DeterministicModuleIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-12-07 21:47:25 +08:00
										 |  |  | 					new DeterministicModuleIdsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-09-17 22:09:58 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "size": { | 
					
						
							|  |  |  | 					const OccurrenceModuleIdsPlugin = require("./ids/OccurrenceModuleIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-04 01:23:27 +08:00
										 |  |  | 					new OccurrenceModuleIdsPlugin({ | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 						prioritiseInitial: true | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 				default: | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						`webpack bug: moduleIds: ${moduleIds} is not implemented` | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-07 20:22:35 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-15 03:48:49 +08:00
										 |  |  | 		const chunkIds = options.optimization.chunkIds; | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 		if (chunkIds) { | 
					
						
							|  |  |  | 			switch (chunkIds) { | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				case "natural": { | 
					
						
							|  |  |  | 					const NaturalChunkIdsPlugin = require("./ids/NaturalChunkIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 					new NaturalChunkIdsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "named": { | 
					
						
							|  |  |  | 					const NamedChunkIdsPlugin = require("./ids/NamedChunkIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 					new NamedChunkIdsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "deterministic": { | 
					
						
							|  |  |  | 					const DeterministicChunkIdsPlugin = require("./ids/DeterministicChunkIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-12-07 21:47:25 +08:00
										 |  |  | 					new DeterministicChunkIdsPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-03-23 03:28:15 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-10-09 19:44:39 +08:00
										 |  |  | 				case "size": { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 					//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2019-10-09 19:44:39 +08:00
										 |  |  | 					const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 					new OccurrenceChunkIdsPlugin({ | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 						prioritiseInitial: true | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-10-09 19:44:39 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				case "total-size": { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 					//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2019-10-09 19:44:39 +08:00
										 |  |  | 					const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 					new OccurrenceChunkIdsPlugin({ | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 						prioritiseInitial: false | 
					
						
							|  |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-10-09 19:44:39 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-07-09 20:31:29 +08:00
										 |  |  | 				default: | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						`webpack bug: chunkIds: ${chunkIds} is not implemented` | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (options.optimization.nodeEnv) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const DefinePlugin = require("./DefinePlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new DefinePlugin({ | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | 				"process.env.NODE_ENV": JSON.stringify(options.optimization.nodeEnv) | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (options.optimization.minimize) { | 
					
						
							|  |  |  | 			for (const minimizer of options.optimization.minimizer) { | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | 				if (typeof minimizer === "function") { | 
					
						
							| 
									
										
										
										
											2018-12-29 17:40:12 +08:00
										 |  |  | 					minimizer.call(compiler, compiler); | 
					
						
							| 
									
										
										
										
											2020-07-13 23:15:20 +08:00
										 |  |  | 				} else if (minimizer !== "...") { | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | 					minimizer.apply(compiler); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-12-13 23:05:21 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (options.performance) { | 
					
						
							| 
									
										
										
										
											2019-03-12 05:18:50 +08:00
										 |  |  | 			const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin"); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 			new SizeLimitsPlugin(options.performance).apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-03 04:49:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new TemplatedPathPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2014-08-22 19:51:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new RecordIdsPlugin({ | 
					
						
							| 
									
										
										
										
											2017-12-01 16:49:07 +08:00
										 |  |  | 			portableIds: options.optimization.portableRecords | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 		new WarnCaseSensitiveModulesPlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2014-03-31 17:33:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 06:36:16 +08:00
										 |  |  | 		const AddManagedPathsPlugin = require("./cache/AddManagedPathsPlugin"); | 
					
						
							|  |  |  | 		new AddManagedPathsPlugin( | 
					
						
							|  |  |  | 			options.snapshot.managedPaths, | 
					
						
							|  |  |  | 			options.snapshot.immutablePaths | 
					
						
							|  |  |  | 		).apply(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		if (options.cache && typeof options.cache === "object") { | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 			const cacheOptions = options.cache; | 
					
						
							|  |  |  | 			switch (cacheOptions.type) { | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 				case "memory": { | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 					//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 					const MemoryCachePlugin = require("./cache/MemoryCachePlugin"); | 
					
						
							|  |  |  | 					new MemoryCachePlugin().apply(compiler); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case "filesystem": { | 
					
						
							| 
									
										
										
										
											2019-08-09 20:46:42 +08:00
										 |  |  | 					const AddBuildDependenciesPlugin = require("./cache/AddBuildDependenciesPlugin"); | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 					for (const key in cacheOptions.buildDependencies) { | 
					
						
							| 
									
										
										
										
											2019-08-09 20:46:42 +08:00
										 |  |  | 						const list = cacheOptions.buildDependencies[key]; | 
					
						
							|  |  |  | 						new AddBuildDependenciesPlugin(list).apply(compiler); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-11-26 20:12:49 +08:00
										 |  |  | 					//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
 | 
					
						
							| 
									
										
										
										
											2018-12-28 03:57:54 +08:00
										 |  |  | 					const MemoryCachePlugin = require("./cache/MemoryCachePlugin"); | 
					
						
							|  |  |  | 					new MemoryCachePlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 					switch (cacheOptions.store) { | 
					
						
							|  |  |  | 						case "pack": { | 
					
						
							|  |  |  | 							const IdleFileCachePlugin = require("./cache/IdleFileCachePlugin"); | 
					
						
							|  |  |  | 							const PackFileCacheStrategy = require("./cache/PackFileCacheStrategy"); | 
					
						
							|  |  |  | 							new IdleFileCachePlugin( | 
					
						
							|  |  |  | 								new PackFileCacheStrategy({ | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 									compiler, | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 									fs: compiler.intermediateFileSystem, | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 									context: options.context, | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 									cacheLocation: cacheOptions.cacheLocation, | 
					
						
							|  |  |  | 									version: cacheOptions.version, | 
					
						
							| 
									
										
										
										
											2019-08-12 19:41:23 +08:00
										 |  |  | 									logger: compiler.getInfrastructureLogger( | 
					
						
							|  |  |  | 										"webpack.cache.PackFileCacheStrategy" | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 									), | 
					
						
							| 
									
										
										
										
											2020-08-26 06:36:16 +08:00
										 |  |  | 									snapshot: options.snapshot | 
					
						
							| 
									
										
										
										
											2019-07-25 21:44:37 +08:00
										 |  |  | 								}), | 
					
						
							|  |  |  | 								cacheOptions.idleTimeout, | 
					
						
							|  |  |  | 								cacheOptions.idleTimeoutForInitialStore | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 							).apply(compiler); | 
					
						
							|  |  |  | 							break; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-10-18 21:23:02 +08:00
										 |  |  | 						default: | 
					
						
							|  |  |  | 							throw new Error("Unhandled value for cache.store"); | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2020-04-01 21:10:56 +08:00
										 |  |  | 					// @ts-expect-error Property 'type' does not exist on type 'never'. ts(2339)
 | 
					
						
							| 
									
										
										
										
											2020-04-01 21:08:46 +08:00
										 |  |  | 					throw new Error(`Unknown cache type ${cacheOptions.type}`); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-23 13:22:44 +08:00
										 |  |  | 		new ResolverCachePlugin().apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-21 04:08:38 +08:00
										 |  |  | 		if (options.ignoreWarnings && options.ignoreWarnings.length > 0) { | 
					
						
							|  |  |  | 			const IgnoreWarningsPlugin = require("./IgnoreWarningsPlugin"); | 
					
						
							|  |  |  | 			new IgnoreWarningsPlugin(options.ignoreWarnings).apply(compiler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		compiler.hooks.afterPlugins.call(compiler); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (!compiler.inputFileSystem) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			throw new Error("No input filesystem provided"); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.resolverFactory.hooks.resolveOptions | 
					
						
							|  |  |  | 			.for("normal") | 
					
						
							|  |  |  | 			.tap("WebpackOptionsApply", resolveOptions => { | 
					
						
							| 
									
										
										
										
											2020-06-18 04:17:14 +08:00
										 |  |  | 				resolveOptions = cleverMerge(options.resolve, resolveOptions); | 
					
						
							|  |  |  | 				resolveOptions.fileSystem = compiler.inputFileSystem; | 
					
						
							|  |  |  | 				return resolveOptions; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		compiler.resolverFactory.hooks.resolveOptions | 
					
						
							|  |  |  | 			.for("context") | 
					
						
							|  |  |  | 			.tap("WebpackOptionsApply", resolveOptions => { | 
					
						
							| 
									
										
										
										
											2020-06-18 04:17:14 +08:00
										 |  |  | 				resolveOptions = cleverMerge(options.resolve, resolveOptions); | 
					
						
							|  |  |  | 				resolveOptions.fileSystem = compiler.inputFileSystem; | 
					
						
							|  |  |  | 				resolveOptions.resolveToContext = true; | 
					
						
							|  |  |  | 				return resolveOptions; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		compiler.resolverFactory.hooks.resolveOptions | 
					
						
							|  |  |  | 			.for("loader") | 
					
						
							|  |  |  | 			.tap("WebpackOptionsApply", resolveOptions => { | 
					
						
							| 
									
										
										
										
											2020-06-18 04:17:14 +08:00
										 |  |  | 				resolveOptions = cleverMerge(options.resolveLoader, resolveOptions); | 
					
						
							|  |  |  | 				resolveOptions.fileSystem = compiler.inputFileSystem; | 
					
						
							|  |  |  | 				return resolveOptions; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		compiler.hooks.afterResolvers.call(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | 		return options; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:49:15 +08:00
										 |  |  | module.exports = WebpackOptionsApply; |