| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const path = require("path"); | 
					
						
							|  |  |  | const Template = require("../Template"); | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | const { cleverMerge } = require("../util/cleverMerge"); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */ | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").Library} Library */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */ | 
					
						
							| 
									
										
										
										
											2020-05-25 18:58:59 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */ | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").ModuleOptions} ModuleOptions */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").Output} Output */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").Target} Target */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Sets a constant default value when undefined | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template {keyof T} P | 
					
						
							|  |  |  |  * @param {T} obj an object | 
					
						
							|  |  |  |  * @param {P} prop a property of this object | 
					
						
							|  |  |  |  * @param {T[P]} value a default value of the property | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const D = (obj, prop, value) => { | 
					
						
							|  |  |  | 	if (obj[prop] === undefined) { | 
					
						
							|  |  |  | 		obj[prop] = value; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Sets a dynamic default value when undefined, by calling the factory function | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template {keyof T} P | 
					
						
							|  |  |  |  * @param {T} obj an object | 
					
						
							|  |  |  |  * @param {P} prop a property of this object | 
					
						
							|  |  |  |  * @param {function(): T[P]} factory a default value factory for the property | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const F = (obj, prop, factory) => { | 
					
						
							|  |  |  | 	if (obj[prop] === undefined) { | 
					
						
							|  |  |  | 		obj[prop] = factory(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Sets a dynamic default value when undefined, by calling the factory function. | 
					
						
							|  |  |  |  * factory must return an array or undefined | 
					
						
							|  |  |  |  * When the current value is already an array an contains "..." it's replaced with | 
					
						
							|  |  |  |  * the result of the factory function | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template {keyof T} P | 
					
						
							|  |  |  |  * @param {T} obj an object | 
					
						
							|  |  |  |  * @param {P} prop a property of this object | 
					
						
							|  |  |  |  * @param {function(): T[P]} factory a default value factory for the property | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const A = (obj, prop, factory) => { | 
					
						
							|  |  |  | 	const value = obj[prop]; | 
					
						
							|  |  |  | 	if (value === undefined) { | 
					
						
							|  |  |  | 		obj[prop] = factory(); | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 	} else if (Array.isArray(value)) { | 
					
						
							|  |  |  | 		/** @type {any[]} */ | 
					
						
							|  |  |  | 		let newArray = undefined; | 
					
						
							|  |  |  | 		for (let i = 0; i < value.length; i++) { | 
					
						
							|  |  |  | 			const item = value[i]; | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 			if (item === "...") { | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 				if (newArray === undefined) { | 
					
						
							|  |  |  | 					newArray = i > 0 ? value.slice(0, i - 1) : []; | 
					
						
							|  |  |  | 					obj[prop] = /** @type {T[P]} */ (/** @type {unknown} */ (newArray)); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 				const items = /** @type {any[]} */ (/** @type {unknown} */ (factory())); | 
					
						
							|  |  |  | 				if (items !== undefined) { | 
					
						
							|  |  |  | 					for (const item of items) { | 
					
						
							|  |  |  | 						newArray.push(item); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 			} else if (newArray !== undefined) { | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 				newArray.push(item); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {WebpackOptions} options options to be modified | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyWebpackOptionsBaseDefaults = options => { | 
					
						
							|  |  |  | 	F(options, "context", () => process.cwd()); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {WebpackOptions} options options to be modified | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyWebpackOptionsDefaults = options => { | 
					
						
							|  |  |  | 	F(options, "context", () => process.cwd()); | 
					
						
							|  |  |  | 	D(options, "target", "web"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const { mode, name, target } = options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const webTarget = | 
					
						
							|  |  |  | 		target === "web" || | 
					
						
							|  |  |  | 		target === "webworker" || | 
					
						
							|  |  |  | 		target === "electron-renderer"; | 
					
						
							|  |  |  | 	const development = mode === "development"; | 
					
						
							|  |  |  | 	const production = mode === "production" || !mode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 	if (typeof options.entry !== "function") { | 
					
						
							|  |  |  | 		for (const key of Object.keys(options.entry)) { | 
					
						
							|  |  |  | 			F( | 
					
						
							|  |  |  | 				options.entry[key], | 
					
						
							|  |  |  | 				"import", | 
					
						
							|  |  |  | 				() => /** @type {[string]} */ (["./src"]) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F(options, "devtool", () => (development ? "eval" : false)); | 
					
						
							|  |  |  | 	D(options, "watch", false); | 
					
						
							|  |  |  | 	D(options, "profile", false); | 
					
						
							|  |  |  | 	D(options, "parallelism", 100); | 
					
						
							|  |  |  | 	D(options, "recordsInputPath", false); | 
					
						
							|  |  |  | 	D(options, "recordsOutputPath", false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F(options, "cache", () => | 
					
						
							|  |  |  | 		development ? { type: /** @type {"memory"} */ ("memory") } : false | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 	applyCacheDefaults(options.cache, { | 
					
						
							|  |  |  | 		name: name || "default", | 
					
						
							|  |  |  | 		mode: mode || "production" | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	const cache = !!options.cache; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	applyExperimentsDefaults(options.experiments); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	applyModuleDefaults(options.module, { | 
					
						
							|  |  |  | 		cache, | 
					
						
							|  |  |  | 		mjs: options.experiments.mjs, | 
					
						
							|  |  |  | 		syncWebAssembly: options.experiments.syncWebAssembly, | 
					
						
							|  |  |  | 		asyncWebAssembly: options.experiments.asyncWebAssembly, | 
					
						
							|  |  |  | 		webTarget | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	applyOutputDefaults(options.output, { | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | 		context: options.context, | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		target, | 
					
						
							|  |  |  | 		outputModule: options.experiments.outputModule, | 
					
						
							|  |  |  | 		development | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 	if (options.output.library) { | 
					
						
							|  |  |  | 		options.output.enabledLibraryTypes.push(options.output.library.type); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 	for (const name of Object.keys(options.entry)) { | 
					
						
							|  |  |  | 		const desc = options.entry[name]; | 
					
						
							|  |  |  | 		if (desc.library) { | 
					
						
							|  |  |  | 			options.output.enabledLibraryTypes.push(desc.library.type); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	F(options, "externalsType", () => | 
					
						
							|  |  |  | 		options.output.library | 
					
						
							|  |  |  | 			? options.output.library.type | 
					
						
							|  |  |  | 			: options.output.module | 
					
						
							|  |  |  | 			? "module" | 
					
						
							|  |  |  | 			: "var" | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	applyNodeDefaults(options.node, { target }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F(options, "performance", () => (production && webTarget ? {} : false)); | 
					
						
							|  |  |  | 	applyPerformanceDefaults(options.performance, { | 
					
						
							|  |  |  | 		production | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	applyOptimizationDefaults(options.optimization, { | 
					
						
							|  |  |  | 		development, | 
					
						
							|  |  |  | 		production, | 
					
						
							|  |  |  | 		records: !!(options.recordsInputPath || options.recordsOutputPath) | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	options.resolve = cleverMerge( | 
					
						
							|  |  |  | 		getResolveDefaults({ | 
					
						
							|  |  |  | 			cache, | 
					
						
							|  |  |  | 			context: options.context, | 
					
						
							|  |  |  | 			webTarget, | 
					
						
							|  |  |  | 			target, | 
					
						
							|  |  |  | 			mode: options.mode | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 		options.resolve | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	options.resolveLoader = cleverMerge( | 
					
						
							| 
									
										
										
										
											2020-07-13 23:15:20 +08:00
										 |  |  | 		getResolveLoaderDefaults({ cache }), | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 		options.resolveLoader | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	applyInfrastructureLoggingDefaults(options.infrastructureLogging); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Experiments} experiments options | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyExperimentsDefaults = experiments => { | 
					
						
							|  |  |  | 	D(experiments, "asset", false); | 
					
						
							|  |  |  | 	D(experiments, "mjs", false); | 
					
						
							|  |  |  | 	D(experiments, "topLevelAwait", false); | 
					
						
							|  |  |  | 	D(experiments, "syncWebAssembly", false); | 
					
						
							|  |  |  | 	D(experiments, "asyncWebAssembly", false); | 
					
						
							|  |  |  | 	D(experiments, "outputModule", false); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  |  * @param {CacheOptions} cache options | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {string} options.name name | 
					
						
							|  |  |  |  * @param {string} options.mode mode | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyCacheDefaults = (cache, { name, mode }) => { | 
					
						
							|  |  |  | 	if (cache === false) return; | 
					
						
							|  |  |  | 	switch (cache.type) { | 
					
						
							|  |  |  | 		case "filesystem": | 
					
						
							|  |  |  | 			F(cache, "name", () => name + "-" + mode); | 
					
						
							|  |  |  | 			D(cache, "version", ""); | 
					
						
							|  |  |  | 			F(cache, "cacheDirectory", () => { | 
					
						
							|  |  |  | 				const pkgDir = require("pkg-dir"); | 
					
						
							|  |  |  | 				const cwd = process.cwd(); | 
					
						
							|  |  |  | 				const dir = pkgDir.sync(cwd); | 
					
						
							|  |  |  | 				if (!dir) { | 
					
						
							|  |  |  | 					return path.resolve(cwd, ".cache/webpack"); | 
					
						
							|  |  |  | 				} else if (process.versions.pnp === "1") { | 
					
						
							|  |  |  | 					return path.resolve(dir, ".pnp/.cache/webpack"); | 
					
						
							| 
									
										
										
										
											2020-02-17 22:48:43 +08:00
										 |  |  | 				} else if (process.versions.pnp === "3") { | 
					
						
							|  |  |  | 					return path.resolve(dir, ".yarn/.cache/webpack"); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					return path.resolve(dir, "node_modules/.cache/webpack"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			F(cache, "cacheLocation", () => | 
					
						
							|  |  |  | 				path.resolve(cache.cacheDirectory, cache.name) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			D(cache, "hashAlgorithm", "md4"); | 
					
						
							|  |  |  | 			D(cache, "store", "pack"); | 
					
						
							|  |  |  | 			D(cache, "idleTimeout", 60000); | 
					
						
							|  |  |  | 			D(cache, "idleTimeoutForInitialStore", 0); | 
					
						
							|  |  |  | 			D(cache.buildDependencies, "defaultWebpack", [ | 
					
						
							|  |  |  | 				path.resolve(__dirname, "..") + path.sep | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	A(cache, "managedPaths", () => { | 
					
						
							| 
									
										
										
										
											2020-02-17 22:48:43 +08:00
										 |  |  | 		if (process.versions.pnp === "3") { | 
					
						
							|  |  |  | 			const match = /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec( | 
					
						
							|  |  |  | 				require.resolve("watchpack") | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			if (match) { | 
					
						
							|  |  |  | 				return [path.resolve(match[1], "unplugged")]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			const match = /^(.+?[\\/]node_modules)[\\/]/.exec( | 
					
						
							|  |  |  | 				// eslint-disable-next-line node/no-extraneous-require
 | 
					
						
							|  |  |  | 				require.resolve("watchpack") | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			if (match) { | 
					
						
							|  |  |  | 				return [match[1]]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return []; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	A(cache, "immutablePaths", () => { | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		if (process.versions.pnp === "1") { | 
					
						
							|  |  |  | 			const match = /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec( | 
					
						
							|  |  |  | 				require.resolve("watchpack") | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			if (match) { | 
					
						
							|  |  |  | 				return [match[1]]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-17 22:48:43 +08:00
										 |  |  | 		} else if (process.versions.pnp === "3") { | 
					
						
							|  |  |  | 			const match = /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec( | 
					
						
							|  |  |  | 				require.resolve("watchpack") | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			if (match) { | 
					
						
							|  |  |  | 				return [match[1]]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return []; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  |  * @param {ModuleOptions} module options | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {boolean} options.cache is caching enabled | 
					
						
							|  |  |  |  * @param {boolean} options.mjs is mjs enabled | 
					
						
							|  |  |  |  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled | 
					
						
							|  |  |  |  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled | 
					
						
							|  |  |  |  * @param {boolean} options.webTarget is web target | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyModuleDefaults = ( | 
					
						
							|  |  |  | 	module, | 
					
						
							|  |  |  | 	{ cache, mjs, syncWebAssembly, asyncWebAssembly, webTarget } | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	D(module, "unknownContextRequest", "."); | 
					
						
							|  |  |  | 	D(module, "unknownContextRegExp", false); | 
					
						
							|  |  |  | 	D(module, "unknownContextRecursive", true); | 
					
						
							|  |  |  | 	D(module, "unknownContextCritical", true); | 
					
						
							|  |  |  | 	D(module, "exprContextRequest", "."); | 
					
						
							|  |  |  | 	D(module, "exprContextRegExp", false); | 
					
						
							|  |  |  | 	D(module, "exprContextRecursive", true); | 
					
						
							|  |  |  | 	D(module, "exprContextCritical", true); | 
					
						
							|  |  |  | 	D(module, "wrappedContextRegExp", /.*/); | 
					
						
							|  |  |  | 	D(module, "wrappedContextRecursive", true); | 
					
						
							|  |  |  | 	D(module, "wrappedContextCritical", false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D(module, "strictExportPresence", false); | 
					
						
							|  |  |  | 	D(module, "strictThisContextOnImports", false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (cache) { | 
					
						
							|  |  |  | 		D(module, "unsafeCache", module => { | 
					
						
							|  |  |  | 			const name = module.nameForCondition(); | 
					
						
							|  |  |  | 			return name && NODE_MODULES_REGEXP.test(name); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		D(module, "unsafeCache", false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	A(module, "defaultRules", () => { | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		/** @type {RuleSetRules} */ | 
					
						
							|  |  |  | 		const rules = [ | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 				type: "javascript/auto" | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				mimetype: "application/node", | 
					
						
							|  |  |  | 				type: "javascript/auto" | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				test: /\.json$/i, | 
					
						
							|  |  |  | 				type: "json" | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				mimetype: "application/json", | 
					
						
							|  |  |  | 				type: "json" | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		]; | 
					
						
							|  |  |  | 		if (mjs) { | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 			const esm = { | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 				type: "javascript/esm", | 
					
						
							|  |  |  | 				resolve: { | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 					byDependency: { | 
					
						
							|  |  |  | 						esm: { | 
					
						
							|  |  |  | 							fullySpecified: true | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 			const commonjs = { | 
					
						
							|  |  |  | 				type: "javascript/dynamic" | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			rules.push( | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					test: /\.mjs$/i, | 
					
						
							|  |  |  | 					...esm | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					test: /\.js$/i, | 
					
						
							|  |  |  | 					descriptionData: { | 
					
						
							|  |  |  | 						type: "module" | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					...esm | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					test: /\.cjs$/i, | 
					
						
							|  |  |  | 					...commonjs | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					test: /\.js$/i, | 
					
						
							|  |  |  | 					descriptionData: { | 
					
						
							|  |  |  | 						type: "commonjs" | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					...commonjs | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					mimetype: { | 
					
						
							|  |  |  | 						or: ["text/javascript", "application/javascript"] | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					...esm | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			rules.push({ | 
					
						
							| 
									
										
										
										
											2020-06-05 19:41:25 +08:00
										 |  |  | 				mimetype: { | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 					or: ["text/javascript", "application/javascript"] | 
					
						
							| 
									
										
										
										
											2020-06-05 19:41:25 +08:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2020-06-05 17:48:17 +08:00
										 |  |  | 				type: "javascript/auto" | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (asyncWebAssembly) { | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 			const wasm = { | 
					
						
							|  |  |  | 				type: "webassembly/async" | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			if (mjs) { | 
					
						
							|  |  |  | 				wasm.rules = [ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						descriptionData: { | 
					
						
							|  |  |  | 							type: "module" | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						resolve: { | 
					
						
							|  |  |  | 							fullySpecified: true | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			rules.push({ | 
					
						
							|  |  |  | 				test: /\.wasm$/i, | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 				...wasm | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			rules.push({ | 
					
						
							|  |  |  | 				mimetype: "application/wasm", | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 				...wasm | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} else if (syncWebAssembly) { | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 			const wasm = { | 
					
						
							|  |  |  | 				type: "webassembly/sync" | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			if (mjs) { | 
					
						
							|  |  |  | 				wasm.rules = [ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						descriptionData: { | 
					
						
							|  |  |  | 							type: "module" | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						resolve: { | 
					
						
							|  |  |  | 							fullySpecified: true | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			rules.push({ | 
					
						
							|  |  |  | 				test: /\.wasm$/i, | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 				...wasm | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			rules.push({ | 
					
						
							|  |  |  | 				mimetype: "application/wasm", | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 				...wasm | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return rules; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Output} output options | 
					
						
							|  |  |  |  * @param {Object} options options | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  |  * @param {string} options.context context | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {Target} options.target target | 
					
						
							|  |  |  |  * @param {boolean} options.outputModule is outputModule experiment enabled | 
					
						
							|  |  |  |  * @param {boolean} options.development is development mode | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | const applyOutputDefaults = ( | 
					
						
							|  |  |  | 	output, | 
					
						
							|  |  |  | 	{ context, target, outputModule, development } | 
					
						
							|  |  |  | ) => { | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Library=} library the library option | 
					
						
							|  |  |  | 	 * @returns {string} a readable library name | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	const getLibraryName = library => { | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 		const libraryName = | 
					
						
							|  |  |  | 			typeof library === "object" && | 
					
						
							|  |  |  | 			library && | 
					
						
							|  |  |  | 			!Array.isArray(library) && | 
					
						
							|  |  |  | 			"type" in library | 
					
						
							|  |  |  | 				? library.name | 
					
						
							|  |  |  | 				: /** @type {LibraryName=} */ (library); | 
					
						
							|  |  |  | 		if (Array.isArray(libraryName)) { | 
					
						
							|  |  |  | 			return libraryName.join("."); | 
					
						
							|  |  |  | 		} else if (typeof libraryName === "object") { | 
					
						
							|  |  |  | 			return getLibraryName(libraryName.root); | 
					
						
							|  |  |  | 		} else if (typeof libraryName === "string") { | 
					
						
							|  |  |  | 			return libraryName; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 		return ""; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | 	F(output, "uniqueName", () => { | 
					
						
							|  |  |  | 		const libraryName = getLibraryName(output.library); | 
					
						
							|  |  |  | 		if (libraryName) return libraryName; | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			const packageInfo = require(`${context}/package.json`); | 
					
						
							|  |  |  | 			return packageInfo.name || ""; | 
					
						
							|  |  |  | 		} catch (e) { | 
					
						
							|  |  |  | 			return ""; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	D(output, "filename", "[name].js"); | 
					
						
							|  |  |  | 	F(output, "module", () => !!outputModule); | 
					
						
							|  |  |  | 	F(output, "iife", () => !output.module); | 
					
						
							|  |  |  | 	D(output, "ecmaVersion", 6); | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 	D(output, "importFunctionName", "import"); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	F(output, "chunkFilename", () => { | 
					
						
							|  |  |  | 		const filename = output.filename; | 
					
						
							|  |  |  | 		if (typeof filename !== "function") { | 
					
						
							|  |  |  | 			const hasName = filename.includes("[name]"); | 
					
						
							|  |  |  | 			const hasId = filename.includes("[id]"); | 
					
						
							|  |  |  | 			const hasChunkHash = filename.includes("[chunkhash]"); | 
					
						
							|  |  |  | 			const hasContentHash = filename.includes("[contenthash]"); | 
					
						
							|  |  |  | 			// Anything changing depending on chunk is fine
 | 
					
						
							|  |  |  | 			if (hasChunkHash || hasContentHash || hasName || hasId) return filename; | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 			// Otherwise prefix "[id]." in front of the basename to make it changing
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return "[id].js"; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2020-02-28 00:49:47 +08:00
										 |  |  | 	D(output, "assetModuleFilename", "[hash][ext][query]"); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	D(output, "webassemblyModuleFilename", "[hash].module.wasm"); | 
					
						
							|  |  |  | 	D(output, "publicPath", ""); | 
					
						
							|  |  |  | 	D(output, "compareBeforeEmit", true); | 
					
						
							|  |  |  | 	F(output, "hotUpdateFunction", () => | 
					
						
							|  |  |  | 		Template.toIdentifier( | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | 			"webpackHotUpdate" + Template.toIdentifier(output.uniqueName) | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		) | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 	F(output, "jsonpFunction", () => | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | 		Template.toIdentifier( | 
					
						
							|  |  |  | 			"webpackJsonp" + Template.toIdentifier(output.uniqueName) | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 	F(output, "chunkCallbackName", () => | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | 		Template.toIdentifier( | 
					
						
							|  |  |  | 			"webpackChunk" + Template.toIdentifier(output.uniqueName) | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	); | 
					
						
							|  |  |  | 	F(output, "globalObject", () => { | 
					
						
							|  |  |  | 		switch (target) { | 
					
						
							|  |  |  | 			case "web": | 
					
						
							|  |  |  | 			case "electron-renderer": | 
					
						
							|  |  |  | 			case "node-webkit": | 
					
						
							|  |  |  | 				return "window"; | 
					
						
							|  |  |  | 			case "webworker": | 
					
						
							|  |  |  | 				return "self"; | 
					
						
							|  |  |  | 			case "node": | 
					
						
							|  |  |  | 			case "async-node": | 
					
						
							|  |  |  | 			case "electron-main": | 
					
						
							|  |  |  | 				return "global"; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				return "self"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2020-02-26 22:50:38 +08:00
										 |  |  | 	F(output, "devtoolNamespace", () => output.uniqueName); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	F(output, "libraryTarget", () => (output.module ? "module" : "var")); | 
					
						
							|  |  |  | 	F(output, "path", () => path.join(process.cwd(), "dist")); | 
					
						
							|  |  |  | 	F(output, "pathinfo", () => development); | 
					
						
							|  |  |  | 	D(output, "sourceMapFilename", "[file].map[query]"); | 
					
						
							|  |  |  | 	D(output, "hotUpdateChunkFilename", "[id].[fullhash].hot-update.js"); | 
					
						
							|  |  |  | 	D(output, "hotUpdateMainFilename", "[fullhash].hot-update.json"); | 
					
						
							|  |  |  | 	D(output, "crossOriginLoading", false); | 
					
						
							| 
									
										
										
										
											2020-06-25 04:05:21 +08:00
										 |  |  | 	F(output, "scriptType", () => (output.module ? "module" : false)); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	D(output, "chunkLoadTimeout", 120000); | 
					
						
							|  |  |  | 	D(output, "hashFunction", "md4"); | 
					
						
							|  |  |  | 	D(output, "hashDigest", "hex"); | 
					
						
							|  |  |  | 	D(output, "hashDigestLength", 20); | 
					
						
							|  |  |  | 	D(output, "strictModuleExceptionHandling", false); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {WebpackNode} node options | 
					
						
							|  |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {Target} options.target target | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyNodeDefaults = (node, { target }) => { | 
					
						
							|  |  |  | 	if (node === false) return; | 
					
						
							|  |  |  | 	F(node, "global", () => { | 
					
						
							|  |  |  | 		switch (target) { | 
					
						
							|  |  |  | 			case "node": | 
					
						
							|  |  |  | 			case "async-node": | 
					
						
							|  |  |  | 			case "electron-main": | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	F(node, "__filename", () => { | 
					
						
							|  |  |  | 		switch (target) { | 
					
						
							|  |  |  | 			case "node": | 
					
						
							|  |  |  | 			case "async-node": | 
					
						
							|  |  |  | 			case "electron-main": | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				return "mock"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	F(node, "__dirname", () => { | 
					
						
							|  |  |  | 		switch (target) { | 
					
						
							|  |  |  | 			case "node": | 
					
						
							|  |  |  | 			case "async-node": | 
					
						
							|  |  |  | 			case "electron-main": | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				return "mock"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Performance} performance options | 
					
						
							|  |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {boolean} options.production is production | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyPerformanceDefaults = (performance, { production }) => { | 
					
						
							|  |  |  | 	if (performance === false) return; | 
					
						
							|  |  |  | 	D(performance, "maxAssetSize", 250000); | 
					
						
							|  |  |  | 	D(performance, "maxEntrypointSize", 250000); | 
					
						
							|  |  |  | 	F(performance, "hints", () => (production ? "warning" : false)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Optimization} optimization options | 
					
						
							|  |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {boolean} options.production is production | 
					
						
							|  |  |  |  * @param {boolean} options.development is development | 
					
						
							|  |  |  |  * @param {boolean} options.records using records | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyOptimizationDefaults = ( | 
					
						
							|  |  |  | 	optimization, | 
					
						
							|  |  |  | 	{ production, development, records } | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	D(optimization, "removeAvailableModules", false); | 
					
						
							|  |  |  | 	D(optimization, "removeEmptyChunks", true); | 
					
						
							|  |  |  | 	D(optimization, "mergeDuplicateChunks", true); | 
					
						
							|  |  |  | 	D(optimization, "flagIncludedChunks", production); | 
					
						
							|  |  |  | 	F(optimization, "moduleIds", () => { | 
					
						
							|  |  |  | 		if (production) return "deterministic"; | 
					
						
							|  |  |  | 		if (development) return "named"; | 
					
						
							|  |  |  | 		return "natural"; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	F(optimization, "chunkIds", () => { | 
					
						
							|  |  |  | 		if (production) return "deterministic"; | 
					
						
							|  |  |  | 		if (development) return "named"; | 
					
						
							|  |  |  | 		return "natural"; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	D(optimization, "sideEffects", true); | 
					
						
							|  |  |  | 	D(optimization, "providedExports", true); | 
					
						
							| 
									
										
										
										
											2020-07-08 18:22:55 +08:00
										 |  |  | 	D(optimization, "usedExports", production); | 
					
						
							|  |  |  | 	D(optimization, "innerGraph", production); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	D(optimization, "mangleExports", production); | 
					
						
							|  |  |  | 	D(optimization, "concatenateModules", production); | 
					
						
							|  |  |  | 	D(optimization, "runtimeChunk", false); | 
					
						
							| 
									
										
										
										
											2020-07-17 21:39:16 +08:00
										 |  |  | 	D(optimization, "emitOnErrors", !production); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	D(optimization, "checkWasmTypes", production); | 
					
						
							|  |  |  | 	D(optimization, "mangleWasmImports", false); | 
					
						
							|  |  |  | 	D(optimization, "portableRecords", records); | 
					
						
							|  |  |  | 	D(optimization, "minimize", production); | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	A(optimization, "minimizer", () => [ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			apply: compiler => { | 
					
						
							|  |  |  | 				// Lazy load the Terser plugin
 | 
					
						
							|  |  |  | 				const TerserPlugin = require("terser-webpack-plugin"); | 
					
						
							| 
									
										
										
										
											2020-08-18 03:32:47 +08:00
										 |  |  | 				new TerserPlugin({ | 
					
						
							|  |  |  | 					terserOptions: { | 
					
						
							|  |  |  | 						compress: { | 
					
						
							|  |  |  | 							passes: 2 | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	]); | 
					
						
							|  |  |  | 	F(optimization, "nodeEnv", () => { | 
					
						
							|  |  |  | 		if (production) return "production"; | 
					
						
							|  |  |  | 		if (development) return "development"; | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	const { splitChunks } = optimization; | 
					
						
							|  |  |  | 	if (splitChunks) { | 
					
						
							|  |  |  | 		D(splitChunks, "hidePathInfo", production); | 
					
						
							|  |  |  | 		D(splitChunks, "chunks", "async"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		D(splitChunks, "usedExports", true); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		D(splitChunks, "minChunks", 1); | 
					
						
							| 
									
										
										
										
											2020-07-13 16:13:27 +08:00
										 |  |  | 		F(splitChunks, "minSize", () => (production ? 20000 : 10000)); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined)); | 
					
						
							| 
									
										
										
										
											2020-07-13 16:13:27 +08:00
										 |  |  | 		F(splitChunks, "enforceSizeThreshold", () => (production ? 50000 : 30000)); | 
					
						
							| 
									
										
										
										
											2020-06-16 22:48:12 +08:00
										 |  |  | 		F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity)); | 
					
						
							|  |  |  | 		F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity)); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		D(splitChunks, "automaticNameDelimiter", "-"); | 
					
						
							|  |  |  | 		const { cacheGroups } = splitChunks; | 
					
						
							|  |  |  | 		F(cacheGroups, "default", () => ({ | 
					
						
							|  |  |  | 			idHint: "", | 
					
						
							|  |  |  | 			reuseExistingChunk: true, | 
					
						
							|  |  |  | 			minChunks: 2, | 
					
						
							|  |  |  | 			priority: -20 | 
					
						
							|  |  |  | 		})); | 
					
						
							|  |  |  | 		F(cacheGroups, "defaultVendors", () => ({ | 
					
						
							|  |  |  | 			idHint: "vendors", | 
					
						
							|  |  |  | 			reuseExistingChunk: true, | 
					
						
							|  |  |  | 			test: NODE_MODULES_REGEXP, | 
					
						
							|  |  |  | 			priority: -10 | 
					
						
							|  |  |  | 		})); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {boolean} options.cache is cache enable | 
					
						
							| 
									
										
										
										
											2020-07-09 05:12:45 +08:00
										 |  |  |  * @param {string} options.context build context | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {boolean} options.webTarget is a web-like target | 
					
						
							| 
									
										
										
										
											2020-05-25 18:58:59 +08:00
										 |  |  |  * @param {Target} options.target target | 
					
						
							|  |  |  |  * @param {Mode} options.mode mode | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  |  * @returns {ResolveOptions} resolve options | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | const getResolveDefaults = ({ cache, context, webTarget, target, mode }) => { | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	/** @type {string[]} */ | 
					
						
							|  |  |  | 	const conditions = ["webpack"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	conditions.push(mode === "development" ? "development" : "production"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (target) { | 
					
						
							|  |  |  | 		case "webworker": | 
					
						
							|  |  |  | 			conditions.push("worker"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "node": | 
					
						
							|  |  |  | 		case "async-node": | 
					
						
							|  |  |  | 		case "node-webkit": | 
					
						
							|  |  |  | 			conditions.push("node"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "electron-main": | 
					
						
							|  |  |  | 		case "electron-preload": | 
					
						
							|  |  |  | 			conditions.push("node"); | 
					
						
							|  |  |  | 			conditions.push("electron"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "electron-renderer": | 
					
						
							|  |  |  | 			conditions.push("electron"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-05-25 18:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 21:57:56 +08:00
										 |  |  | 	const jsExtensions = [".js", ".json", ".wasm"]; | 
					
						
							| 
									
										
										
										
											2020-05-25 18:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 	/** @type {function(): ResolveOptions} */ | 
					
						
							|  |  |  | 	const cjsDeps = () => ({ | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 		aliasFields: webTarget ? ["browser"] : [], | 
					
						
							|  |  |  | 		mainFields: webTarget ? ["browser", "module", "..."] : ["module", "..."], | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 		conditionNames: webTarget | 
					
						
							|  |  |  | 			? ["require", "module", "browser", "..."] | 
					
						
							| 
									
										
										
										
											2020-07-13 23:46:50 +08:00
										 |  |  | 			: ["require", "module", "..."], | 
					
						
							|  |  |  | 		extensions: [...jsExtensions] | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 	/** @type {function(): ResolveOptions} */ | 
					
						
							|  |  |  | 	const esmDeps = () => ({ | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 		aliasFields: webTarget ? ["browser"] : [], | 
					
						
							|  |  |  | 		mainFields: webTarget ? ["browser", "module", "..."] : ["module", "..."], | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 		conditionNames: webTarget | 
					
						
							|  |  |  | 			? ["import", "module", "browser", "..."] | 
					
						
							| 
									
										
										
										
											2020-07-13 23:46:50 +08:00
										 |  |  | 			: ["import", "module", "..."], | 
					
						
							|  |  |  | 		extensions: [...jsExtensions] | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** @type {ResolveOptions} */ | 
					
						
							|  |  |  | 	const resolveOptions = { | 
					
						
							|  |  |  | 		cache, | 
					
						
							|  |  |  | 		modules: ["node_modules"], | 
					
						
							|  |  |  | 		conditionNames: conditions, | 
					
						
							|  |  |  | 		mainFiles: ["index"], | 
					
						
							| 
									
										
										
										
											2020-07-13 23:46:50 +08:00
										 |  |  | 		extensions: [], | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 		aliasFields: [], | 
					
						
							|  |  |  | 		exportsFields: ["exports"], | 
					
						
							|  |  |  | 		roots: [context], | 
					
						
							|  |  |  | 		mainFields: ["main"], | 
					
						
							|  |  |  | 		byDependency: { | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 			wasm: esmDeps(), | 
					
						
							|  |  |  | 			esm: esmDeps(), | 
					
						
							|  |  |  | 			commonjs: cjsDeps(), | 
					
						
							|  |  |  | 			amd: cjsDeps(), | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 			// for backward-compat: loadModule
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 			loader: cjsDeps(), | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 			// for backward-compat: Custom Dependency
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 			unknown: cjsDeps(), | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 			// for backward-compat: getResolve without dependencyType
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:28:55 +08:00
										 |  |  | 			undefined: cjsDeps() | 
					
						
							| 
									
										
										
										
											2020-05-25 18:58:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-05-25 18:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | 	return resolveOptions; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Object} options options | 
					
						
							|  |  |  |  * @param {boolean} options.cache is cache enable | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  |  * @returns {ResolveOptions} resolve options | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-11 16:30:18 +08:00
										 |  |  | const getResolveLoaderDefaults = ({ cache }) => { | 
					
						
							|  |  |  | 	/** @type {ResolveOptions} */ | 
					
						
							|  |  |  | 	const resolveOptions = { | 
					
						
							|  |  |  | 		cache, | 
					
						
							|  |  |  | 		conditionNames: ["loader", "require", "node"], | 
					
						
							|  |  |  | 		exportsFields: ["exports"], | 
					
						
							|  |  |  | 		mainFields: ["loader", "main"], | 
					
						
							|  |  |  | 		extensions: [".js"], | 
					
						
							|  |  |  | 		mainFiles: ["index"] | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return resolveOptions; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {InfrastructureLogging} infrastructureLogging options | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const applyInfrastructureLoggingDefaults = infrastructureLogging => { | 
					
						
							|  |  |  | 	D(infrastructureLogging, "level", "info"); | 
					
						
							|  |  |  | 	D(infrastructureLogging, "debug", false); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.applyWebpackOptionsBaseDefaults = applyWebpackOptionsBaseDefaults; | 
					
						
							|  |  |  | exports.applyWebpackOptionsDefaults = applyWebpackOptionsDefaults; |