| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-21 01:14:41 +08:00
										 |  |  | const findCacheDir = require("find-cache-dir"); | 
					
						
							|  |  |  | const os = require("os"); | 
					
						
							| 
									
										
										
										
											2019-03-21 10:26:08 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | const OptionsDefaulter = require("./OptionsDefaulter"); | 
					
						
							|  |  |  | const Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2018-01-03 23:26:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-31 17:11:08 +08:00
										 |  |  | const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 23:26:55 +08:00
										 |  |  | const isProductionLikeMode = options => { | 
					
						
							|  |  |  | 	return options.mode === "production" || !options.mode; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 21:16:01 +08:00
										 |  |  | const isWebLikeTarget = options => { | 
					
						
							|  |  |  | 	return options.target === "web" || options.target === "webworker"; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-09 23:28:32 +08:00
										 |  |  | const getDevtoolNamespace = library => { | 
					
						
							|  |  |  | 	// if options.output.library is a string
 | 
					
						
							|  |  |  | 	if (Array.isArray(library)) { | 
					
						
							|  |  |  | 		return library.join("."); | 
					
						
							|  |  |  | 	} else if (typeof library === "object") { | 
					
						
							|  |  |  | 		return getDevtoolNamespace(library.root); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return library || ""; | 
					
						
							| 
									
										
										
										
											2018-07-09 23:50:13 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-07-09 23:28:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | class WebpackOptionsDefaulter extends OptionsDefaulter { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							|  |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-12-19 04:18:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.set("experiments", "call", value => ({ ...value })); | 
					
						
							| 
									
										
										
										
											2019-07-16 19:16:27 +08:00
										 |  |  | 		this.set("experiments.asset", false); | 
					
						
							| 
									
										
										
										
											2019-06-04 17:26:04 +08:00
										 |  |  | 		this.set("experiments.mjs", false); | 
					
						
							| 
									
										
										
										
											2019-06-05 22:10:08 +08:00
										 |  |  | 		this.set("experiments.importAwait", false); | 
					
						
							|  |  |  | 		this.set("experiments.importAsync", false); | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 		this.set("experiments.topLevelAwait", false); | 
					
						
							|  |  |  | 		this.set("experiments.syncWebAssembly", false); | 
					
						
							|  |  |  | 		this.set("experiments.asyncWebAssembly", false); | 
					
						
							| 
									
										
										
										
											2019-06-04 17:26:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 23:48:39 +08:00
										 |  |  | 		this.set("entry", "./src"); | 
					
						
							| 
									
										
										
										
											2017-12-19 04:18:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-05 17:06:32 +08:00
										 |  |  | 		this.set("devtool", "make", options => | 
					
						
							|  |  |  | 			options.mode === "development" ? "eval" : false | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 		this.set("cache", "call", (value, options) => { | 
					
						
							|  |  |  | 			if (value === undefined) { | 
					
						
							|  |  |  | 				value = options.mode === "development"; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (value === true) { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					type: "memory" | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-10 16:07:51 +08:00
										 |  |  | 			if (!value) { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 			value = { ...value }; | 
					
						
							| 
									
										
										
										
											2018-10-10 16:07:51 +08:00
										 |  |  | 			if (value.type === "filesystem") { | 
					
						
							|  |  |  | 				if (value.name === undefined) { | 
					
						
							|  |  |  | 					value.name = | 
					
						
							|  |  |  | 						(options.name || "default") + "-" + (options.mode || "production"); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 				if (value.version === undefined) { | 
					
						
							|  |  |  | 					value.version = ""; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (value.cacheDirectory === undefined) { | 
					
						
							| 
									
										
										
										
											2019-03-21 01:14:41 +08:00
										 |  |  | 					value.cacheDirectory = | 
					
						
							|  |  |  | 						findCacheDir({ name: "webpack" }) || os.tmpdir(); | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				if (value.cacheLocation === undefined) { | 
					
						
							|  |  |  | 					value.cacheLocation = path.resolve(value.cacheDirectory, value.name); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (value.hashAlgorithm === undefined) { | 
					
						
							|  |  |  | 					value.hashAlgorithm = "md4"; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (value.store === undefined) { | 
					
						
							|  |  |  | 					value.store = "pack"; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (value.idleTimeout === undefined) { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:45:00 +08:00
										 |  |  | 					value.idleTimeout = 60000; | 
					
						
							| 
									
										
										
										
											2019-01-26 02:21:45 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				if (value.idleTimeoutForInitialStore === undefined) { | 
					
						
							|  |  |  | 					value.idleTimeoutForInitialStore = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-08-09 20:46:42 +08:00
										 |  |  | 				value.buildDependencies = Object.assign({}, value.buildDependencies); | 
					
						
							|  |  |  | 				if (value.buildDependencies.defaultWebpack === undefined) { | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 					value.buildDependencies.defaultWebpack = [__dirname + path.sep]; | 
					
						
							| 
									
										
										
										
											2019-08-09 20:46:42 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-10-10 16:07:51 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-09 20:30:59 +08:00
										 |  |  | 			return value; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 		this.set("cache.managedPaths", "make", () => { | 
					
						
							|  |  |  | 			const match = /^(.+?[\\/]node_modules[\\/])/.exec( | 
					
						
							|  |  |  | 				// eslint-disable-next-line node/no-extraneous-require
 | 
					
						
							|  |  |  | 				require.resolve("watchpack") | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			if (match) { | 
					
						
							|  |  |  | 				return [match[1]]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("context", process.cwd()); | 
					
						
							|  |  |  | 		this.set("target", "web"); | 
					
						
							| 
									
										
										
										
											2014-03-11 23:08:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.set("module", "call", value => ({ ...value })); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("module.unknownContextRequest", "."); | 
					
						
							|  |  |  | 		this.set("module.unknownContextRegExp", false); | 
					
						
							|  |  |  | 		this.set("module.unknownContextRecursive", true); | 
					
						
							|  |  |  | 		this.set("module.unknownContextCritical", true); | 
					
						
							|  |  |  | 		this.set("module.exprContextRequest", "."); | 
					
						
							|  |  |  | 		this.set("module.exprContextRegExp", false); | 
					
						
							|  |  |  | 		this.set("module.exprContextRecursive", true); | 
					
						
							|  |  |  | 		this.set("module.exprContextCritical", true); | 
					
						
							|  |  |  | 		this.set("module.wrappedContextRegExp", /.*/); | 
					
						
							|  |  |  | 		this.set("module.wrappedContextRecursive", true); | 
					
						
							|  |  |  | 		this.set("module.wrappedContextCritical", false); | 
					
						
							| 
									
										
										
										
											2017-02-23 05:31:46 +08:00
										 |  |  | 		this.set("module.strictExportPresence", false); | 
					
						
							| 
									
										
										
										
											2017-05-21 15:13:33 +08:00
										 |  |  | 		this.set("module.strictThisContextOnImports", false); | 
					
						
							| 
									
										
										
										
											2018-10-31 17:11:08 +08:00
										 |  |  | 		this.set("module.unsafeCache", "make", options => { | 
					
						
							|  |  |  | 			if (options.cache) { | 
					
						
							|  |  |  | 				return module => { | 
					
						
							|  |  |  | 					const name = module.nameForCondition(); | 
					
						
							|  |  |  | 					return name && NODE_MODULES_REGEXP.test(name); | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.set("module.rules", []); | 
					
						
							| 
									
										
										
										
											2019-06-04 17:26:04 +08:00
										 |  |  | 		this.set("module.defaultRules", "make", options => | 
					
						
							|  |  |  | 			[ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					type: "javascript/auto", | 
					
						
							|  |  |  | 					resolve: {} | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				options.experiments.mjs && { | 
					
						
							|  |  |  | 					test: /\.mjs$/i, | 
					
						
							|  |  |  | 					type: "javascript/esm", | 
					
						
							|  |  |  | 					resolve: { | 
					
						
							|  |  |  | 						mainFields: | 
					
						
							|  |  |  | 							options.target === "web" || | 
					
						
							|  |  |  | 							options.target === "webworker" || | 
					
						
							|  |  |  | 							options.target === "electron-renderer" | 
					
						
							|  |  |  | 								? ["browser", "main"] | 
					
						
							|  |  |  | 								: ["main"] | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					test: /\.json$/i, | 
					
						
							|  |  |  | 					type: "json" | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 				options.experiments.syncWebAssembly && { | 
					
						
							|  |  |  | 					test: /\.wasm$/i, | 
					
						
							| 
									
										
										
										
											2019-07-15 21:03:29 +08:00
										 |  |  | 					type: "webassembly/sync" | 
					
						
							| 
									
										
										
										
											2019-06-05 19:25:15 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				options.experiments.asyncWebAssembly && { | 
					
						
							| 
									
										
										
										
											2019-06-04 17:26:04 +08:00
										 |  |  | 					test: /\.wasm$/i, | 
					
						
							| 
									
										
										
										
											2019-07-15 21:03:29 +08:00
										 |  |  | 					type: "webassembly/async" | 
					
						
							| 
									
										
										
										
											2018-02-10 01:01:31 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-06-04 17:26:04 +08:00
										 |  |  | 			].filter(Boolean) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output", "call", (value, options) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (typeof value === "string") { | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					filename: value | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (typeof value !== "object") { | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 				return {}; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 				return { ...value }; | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-19 04:18:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.filename", "[name].js"); | 
					
						
							| 
									
										
										
										
											2017-12-31 08:42:01 +08:00
										 |  |  | 		this.set("output.chunkFilename", "make", options => { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:12:01 +08:00
										 |  |  | 			const filename = options.output.filename; | 
					
						
							| 
									
										
										
										
											2018-03-07 15:56:04 +08:00
										 |  |  | 			if (typeof filename !== "function") { | 
					
						
							|  |  |  | 				const hasName = filename.includes("[name]"); | 
					
						
							|  |  |  | 				const hasId = filename.includes("[id]"); | 
					
						
							|  |  |  | 				const hasChunkHash = filename.includes("[chunkhash]"); | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 				const hasContentHash = filename.includes("[contenthash]"); | 
					
						
							| 
									
										
										
										
											2018-03-07 15:56:04 +08:00
										 |  |  | 				// Anything changing depending on chunk is fine
 | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 				if (hasChunkHash || hasContentHash || hasName || hasId) return filename; | 
					
						
							| 
									
										
										
										
											2018-03-07 15:56:04 +08:00
										 |  |  | 				// Elsewise prefix "[id]." in front of the basename to make it changing
 | 
					
						
							|  |  |  | 				return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2"); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-08 03:23:00 +08:00
										 |  |  | 			return "[id].js"; | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-16 19:16:27 +08:00
										 |  |  | 		this.set("output.assetModuleFilename", "[hash][ext]"); | 
					
						
							| 
									
										
										
										
											2018-10-30 18:59:22 +08:00
										 |  |  | 		this.set("output.webassemblyModuleFilename", "[hash].module.wasm"); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.library", ""); | 
					
						
							| 
									
										
										
										
											2017-12-31 08:42:01 +08:00
										 |  |  | 		this.set("output.hotUpdateFunction", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			return Template.toIdentifier( | 
					
						
							|  |  |  | 				"webpackHotUpdate" + Template.toIdentifier(options.output.library) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-31 08:42:01 +08:00
										 |  |  | 		this.set("output.jsonpFunction", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			return Template.toIdentifier( | 
					
						
							|  |  |  | 				"webpackJsonp" + Template.toIdentifier(options.output.library) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-03 22:41:45 +08:00
										 |  |  | 		this.set("output.chunkCallbackName", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			return Template.toIdentifier( | 
					
						
							|  |  |  | 				"webpackChunk" + Template.toIdentifier(options.output.library) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("output.globalObject", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			switch (options.target) { | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | 				case "web": | 
					
						
							|  |  |  | 				case "electron-renderer": | 
					
						
							| 
									
										
										
										
											2018-04-15 03:27:24 +08:00
										 |  |  | 				case "node-webkit": | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | 					return "window"; | 
					
						
							|  |  |  | 				case "webworker": | 
					
						
							|  |  |  | 					return "self"; | 
					
						
							|  |  |  | 				case "node": | 
					
						
							|  |  |  | 				case "async-node": | 
					
						
							|  |  |  | 				case "electron-main": | 
					
						
							|  |  |  | 					return "global"; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					return "self"; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-31 08:42:01 +08:00
										 |  |  | 		this.set("output.devtoolNamespace", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-07-09 23:28:32 +08:00
										 |  |  | 			return getDevtoolNamespace(options.output.library); | 
					
						
							| 
									
										
										
										
											2017-10-20 04:23:28 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.libraryTarget", "var"); | 
					
						
							| 
									
										
										
										
											2017-12-19 04:18:07 +08:00
										 |  |  | 		this.set("output.path", path.join(process.cwd(), "dist")); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set( | 
					
						
							|  |  |  | 			"output.pathinfo", | 
					
						
							|  |  |  | 			"make", | 
					
						
							|  |  |  | 			options => options.mode === "development" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.sourceMapFilename", "[file].map[query]"); | 
					
						
							| 
									
										
										
										
											2018-12-26 03:10:49 +08:00
										 |  |  | 		this.set("output.hotUpdateChunkFilename", "[id].[fullhash].hot-update.js"); | 
					
						
							|  |  |  | 		this.set("output.hotUpdateMainFilename", "[fullhash].hot-update.json"); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.crossOriginLoading", false); | 
					
						
							| 
									
										
										
										
											2018-01-05 03:34:59 +08:00
										 |  |  | 		this.set("output.jsonpScriptType", false); | 
					
						
							| 
									
										
										
										
											2017-05-11 16:41:38 +08:00
										 |  |  | 		this.set("output.chunkLoadTimeout", 120000); | 
					
						
							| 
									
										
										
										
											2018-02-22 18:27:11 +08:00
										 |  |  | 		this.set("output.hashFunction", "md4"); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.hashDigest", "hex"); | 
					
						
							|  |  |  | 		this.set("output.hashDigestLength", 20); | 
					
						
							|  |  |  | 		this.set("output.strictModuleExceptionHandling", false); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 23:15:03 +08:00
										 |  |  | 		this.set("node", "call", value => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (typeof value === "boolean") { | 
					
						
							| 
									
										
										
										
											2017-09-06 23:15:03 +08:00
										 |  |  | 				return value; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 				return { ...value }; | 
					
						
							| 
									
										
										
										
											2017-09-06 23:15:03 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-05-22 21:54:44 +08:00
										 |  |  | 		this.set("node.global", "make", options => { | 
					
						
							|  |  |  | 			switch (options.target) { | 
					
						
							|  |  |  | 				case "node": | 
					
						
							|  |  |  | 				case "async-node": | 
					
						
							|  |  |  | 				case "electron-main": | 
					
						
							|  |  |  | 					return false; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("node.__filename", "make", options => { | 
					
						
							|  |  |  | 			switch (options.target) { | 
					
						
							|  |  |  | 				case "node": | 
					
						
							|  |  |  | 				case "async-node": | 
					
						
							|  |  |  | 				case "electron-main": | 
					
						
							|  |  |  | 					return false; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					return "mock"; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("node.__dirname", "make", options => { | 
					
						
							|  |  |  | 			switch (options.target) { | 
					
						
							|  |  |  | 				case "node": | 
					
						
							|  |  |  | 				case "async-node": | 
					
						
							|  |  |  | 				case "electron-main": | 
					
						
							|  |  |  | 					return false; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					return "mock"; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-03 04:49:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 23:48:33 +08:00
										 |  |  | 		this.set("performance", "call", (value, options) => { | 
					
						
							|  |  |  | 			if (value === false) return false; | 
					
						
							|  |  |  | 			if ( | 
					
						
							|  |  |  | 				value === undefined && | 
					
						
							|  |  |  | 				(!isProductionLikeMode(options) || !isWebLikeTarget(options)) | 
					
						
							|  |  |  | 			) | 
					
						
							| 
									
										
										
										
											2018-03-12 21:16:01 +08:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 			return { ...value }; | 
					
						
							| 
									
										
										
										
											2017-09-06 23:15:03 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("performance.maxAssetSize", 250000); | 
					
						
							|  |  |  | 		this.set("performance.maxEntrypointSize", 250000); | 
					
						
							| 
									
										
										
										
											2019-02-05 17:06:32 +08:00
										 |  |  | 		this.set("performance.hints", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) ? "warning" : false | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.set("optimization", "call", value => ({ ...value })); | 
					
						
							| 
									
										
										
										
											2019-07-25 17:25:57 +08:00
										 |  |  | 		this.set("optimization.removeAvailableModules", false); | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | 		this.set("optimization.removeEmptyChunks", true); | 
					
						
							| 
									
										
										
										
											2018-02-13 19:38:10 +08:00
										 |  |  | 		this.set("optimization.mergeDuplicateChunks", true); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set("optimization.flagIncludedChunks", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-25 21:00:41 +08:00
										 |  |  | 		this.set("optimization.moduleIds", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-10-25 22:53:35 +08:00
										 |  |  | 			if (isProductionLikeMode(options)) return "deterministic"; | 
					
						
							| 
									
										
										
										
											2018-07-25 21:00:41 +08:00
										 |  |  | 			if (options.mode === "development") return "named"; | 
					
						
							|  |  |  | 			return "natural"; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("optimization.chunkIds", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 			if (isProductionLikeMode(options)) return "deterministic"; | 
					
						
							| 
									
										
										
										
											2018-07-25 21:00:41 +08:00
										 |  |  | 			if (options.mode === "development") return "named"; | 
					
						
							|  |  |  | 			return "natural"; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set("optimization.sideEffects", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | 		this.set("optimization.providedExports", true); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set("optimization.usedExports", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-01-28 17:40:32 +08:00
										 |  |  | 		this.set("optimization.mangleExports", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set("optimization.concatenateModules", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.set("optimization.splitChunks", {}); | 
					
						
							| 
									
										
										
										
											2018-07-04 15:59:22 +08:00
										 |  |  | 		this.set("optimization.splitChunks.hidePathInfo", "make", options => { | 
					
						
							|  |  |  | 			return isProductionLikeMode(options); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.set("optimization.splitChunks.chunks", "async"); | 
					
						
							| 
									
										
										
										
											2018-12-11 03:50:37 +08:00
										 |  |  | 		this.set("optimization.splitChunks.minChunks", 1); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:31:04 +08:00
										 |  |  | 		this.set("optimization.splitChunks.minSize", "make", options => { | 
					
						
							|  |  |  | 			return isProductionLikeMode(options) ? 30000 : 10000; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-05-13 19:10:23 +08:00
										 |  |  | 		this.set("optimization.splitChunks.minRemainingSize", "make", options => { | 
					
						
							|  |  |  | 			return options.mode === "development" ? 0 : undefined; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:31:04 +08:00
										 |  |  | 		this.set("optimization.splitChunks.maxAsyncRequests", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-06-26 18:00:48 +08:00
										 |  |  | 			return isProductionLikeMode(options) ? 6 : Infinity; | 
					
						
							| 
									
										
										
										
											2018-04-27 20:31:04 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-12-07 21:43:24 +08:00
										 |  |  | 		this.set("optimization.splitChunks.automaticNameDelimiter", "-"); | 
					
						
							| 
									
										
										
										
											2018-04-27 20:31:04 +08:00
										 |  |  | 		this.set("optimization.splitChunks.maxInitialRequests", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-06-26 18:00:48 +08:00
										 |  |  | 			return isProductionLikeMode(options) ? 4 : Infinity; | 
					
						
							| 
									
										
										
										
											2018-04-27 20:31:04 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-20 20:11:02 +08:00
										 |  |  | 		this.set("optimization.splitChunks.cacheGroups", {}); | 
					
						
							|  |  |  | 		this.set("optimization.splitChunks.cacheGroups.default", { | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 			idHint: "", | 
					
						
							| 
									
										
										
										
											2018-01-20 20:11:02 +08:00
										 |  |  | 			reuseExistingChunk: true, | 
					
						
							|  |  |  | 			minChunks: 2, | 
					
						
							|  |  |  | 			priority: -20 | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-07-02 16:15:13 +08:00
										 |  |  | 		this.set("optimization.splitChunks.cacheGroups.defaultVendors", { | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 			idHint: "vendors", | 
					
						
							| 
									
										
										
										
											2018-10-31 17:11:08 +08:00
										 |  |  | 			test: NODE_MODULES_REGEXP, | 
					
						
							| 
									
										
										
										
											2018-01-20 20:11:02 +08:00
										 |  |  | 			priority: -10 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-02 00:50:03 +08:00
										 |  |  | 		this.set("optimization.runtimeChunk", "call", value => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (value === "single") { | 
					
						
							| 
									
										
										
										
											2018-02-02 00:50:03 +08:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					name: "runtime" | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (value === true || value === "multiple") { | 
					
						
							| 
									
										
										
										
											2018-02-02 00:50:03 +08:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					name: entrypoint => `runtime~${entrypoint.name}` | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return value; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set("optimization.noEmitOnErrors", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-06-05 02:14:08 +08:00
										 |  |  | 		this.set("optimization.checkWasmTypes", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-06-06 05:38:29 +08:00
										 |  |  | 		this.set("optimization.mangleWasmImports", false); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.set( | 
					
						
							|  |  |  | 			"optimization.portableRecords", | 
					
						
							|  |  |  | 			"make", | 
					
						
							|  |  |  | 			options => | 
					
						
							|  |  |  | 				!!( | 
					
						
							|  |  |  | 					options.recordsInputPath || | 
					
						
							|  |  |  | 					options.recordsOutputPath || | 
					
						
							|  |  |  | 					options.recordsPath | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		this.set("optimization.minimize", "make", options => | 
					
						
							|  |  |  | 			isProductionLikeMode(options) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		this.set("optimization.minimizer", "make", options => [ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				apply: compiler => { | 
					
						
							| 
									
										
										
										
											2018-09-10 07:16:35 +08:00
										 |  |  | 					// Lazy load the Terser plugin
 | 
					
						
							|  |  |  | 					const TerserPlugin = require("terser-webpack-plugin"); | 
					
						
							| 
									
										
										
										
											2018-03-02 08:08:49 +08:00
										 |  |  | 					const SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin"); | 
					
						
							| 
									
										
										
										
											2018-09-10 07:16:35 +08:00
										 |  |  | 					new TerserPlugin({ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						cache: true, | 
					
						
							|  |  |  | 						parallel: true, | 
					
						
							| 
									
										
										
										
											2018-03-02 08:08:49 +08:00
										 |  |  | 						sourceMap: | 
					
						
							|  |  |  | 							(options.devtool && /source-?map/.test(options.devtool)) || | 
					
						
							|  |  |  | 							(options.plugins && | 
					
						
							|  |  |  | 								options.plugins.some(p => p instanceof SourceMapDevToolPlugin)) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					}).apply(compiler); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-12-13 23:05:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		]); | 
					
						
							| 
									
										
										
										
											2018-06-04 15:49:08 +08:00
										 |  |  | 		this.set("optimization.nodeEnv", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-06-27 17:18:20 +08:00
										 |  |  | 			if (options.mode === "none") { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				return options.mode || "production"; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-04 15:49:08 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.set("resolve", "call", value => ({ ...value })); | 
					
						
							| 
									
										
										
										
											2018-10-31 20:53:38 +08:00
										 |  |  | 		this.set("resolve.cache", "make", options => !!options.cache); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("resolve.modules", ["node_modules"]); | 
					
						
							| 
									
										
										
										
											2019-06-04 17:26:04 +08:00
										 |  |  | 		this.set("resolve.extensions", "make", options => | 
					
						
							|  |  |  | 			[options.experiments.mjs && ".mjs", ".js", ".json", ".wasm"].filter( | 
					
						
							|  |  |  | 				Boolean | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-06-02 19:41:25 +08:00
										 |  |  | 		this.set("resolve.mainFiles", ["index"]); | 
					
						
							| 
									
										
										
										
											2017-12-31 08:42:01 +08:00
										 |  |  | 		this.set("resolve.aliasFields", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-09-16 20:49:25 +08:00
										 |  |  | 			if ( | 
					
						
							|  |  |  | 				options.target === "web" || | 
					
						
							|  |  |  | 				options.target === "webworker" || | 
					
						
							|  |  |  | 				options.target === "electron-renderer" | 
					
						
							|  |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return ["browser"]; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				return []; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-31 08:42:01 +08:00
										 |  |  | 		this.set("resolve.mainFields", "make", options => { | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:57 +08:00
										 |  |  | 			if ( | 
					
						
							|  |  |  | 				options.target === "web" || | 
					
						
							|  |  |  | 				options.target === "webworker" || | 
					
						
							|  |  |  | 				options.target === "electron-renderer" | 
					
						
							|  |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return ["browser", "module", "main"]; | 
					
						
							| 
									
										
										
										
											2018-03-21 17:11:57 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				return ["module", "main"]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-06 18:10:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.set("resolveLoader", "call", value => ({ ...value })); | 
					
						
							| 
									
										
										
										
											2018-10-31 20:53:38 +08:00
										 |  |  | 		this.set("resolveLoader.cache", "make", options => !!options.cache); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("resolveLoader.mainFields", ["loader", "main"]); | 
					
						
							| 
									
										
										
										
											2019-01-18 03:08:50 +08:00
										 |  |  | 		this.set("resolveLoader.extensions", [".js"]); | 
					
						
							| 
									
										
										
										
											2017-06-02 19:41:25 +08:00
										 |  |  | 		this.set("resolveLoader.mainFiles", ["index"]); | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.set("infrastructureLogging", "call", value => | 
					
						
							|  |  |  | 			Object.assign({}, value) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		this.set("infrastructureLogging.level", "info"); | 
					
						
							|  |  |  | 		this.set("infrastructureLogging.debug", false); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-13 18:02:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | module.exports = WebpackOptionsDefaulter; |