| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 21:39:16 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | const normalizeEcmaVersion = require("../util/normalizeEcmaVersion"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").EntryStatic} EntryStatic */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */ | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").OptimizationRuntimeChunk} OptimizationRuntimeChunk */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").OptimizationRuntimeChunkNormalized} OptimizationRuntimeChunkNormalized */ | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputNormalized */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */ | 
					
						
							|  |  |  | /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 21:39:16 +08:00
										 |  |  | const handledDeprecatedNoEmitOnErrors = util.deprecate( | 
					
						
							|  |  |  | 	(noEmitOnErrors, emitOnErrors) => { | 
					
						
							|  |  |  | 		if (emitOnErrors !== undefined && !noEmitOnErrors === !emitOnErrors) { | 
					
						
							|  |  |  | 			throw new Error( | 
					
						
							|  |  |  | 				"Conflicting use of 'optimization.noEmitOnErrors' and 'optimization.emitOnErrors'. Remove deprecated 'optimization.noEmitOnErrors' from config." | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return !noEmitOnErrors; | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"optimization.noEmitOnErrors is deprecated in favor of optimization.emitOnErrors", | 
					
						
							|  |  |  | 	"DEP_WEBPACK_CONFIGURATION_OPTIMIZATION_NO_EMIT_ON_ERRORS" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template R | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @param {T|undefined} value value or not | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {function(T): R} fn nested handler | 
					
						
							|  |  |  |  * @returns {R} result value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const nestedConfig = (value, fn) => | 
					
						
							|  |  |  | 	value === undefined ? fn(/** @type {T} */ ({})) : fn(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template R | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @param {T|undefined} value value or not | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {function(T): R} fn nested handler | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @returns {R|undefined} result value | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const optionalNestedConfig = (value, fn) => | 
					
						
							|  |  |  | 	value === undefined ? undefined : fn(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template R | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @param {T[]|undefined} value array or not | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {function(T[]): R[]} fn nested handler | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @returns {R[]|undefined} cloned value | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const nestedArray = (value, fn) => (Array.isArray(value) ? fn(value) : fn([])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template R | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @param {T[]|undefined} value array or not | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  * @param {function(T[]): R[]} fn nested handler | 
					
						
							| 
									
										
										
										
											2020-05-08 05:44:15 +08:00
										 |  |  |  * @returns {R[]|undefined} cloned value | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const optionalNestedArray = (value, fn) => | 
					
						
							|  |  |  | 	Array.isArray(value) ? fn(value) : undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-28 22:52:30 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template R | 
					
						
							|  |  |  |  * @param {Record<string, T>|undefined} value value or not | 
					
						
							|  |  |  |  * @param {function(T): R} fn nested handler | 
					
						
							|  |  |  |  * @returns {Record<string, R>} result value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const keyedNestedConfig = (value, fn) => | 
					
						
							|  |  |  | 	value === undefined | 
					
						
							|  |  |  | 		? {} | 
					
						
							|  |  |  | 		: Object.keys(value).reduce( | 
					
						
							|  |  |  | 				(obj, key) => ((obj[key] = fn(value[key])), obj), | 
					
						
							|  |  |  | 				/** @type {Record<string, R>} */ ({}) | 
					
						
							|  |  |  | 		  ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {WebpackOptions} config input config | 
					
						
							|  |  |  |  * @returns {WebpackOptionsNormalized} normalized options | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getNormalizedWebpackOptions = config => { | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		amd: config.amd, | 
					
						
							|  |  |  | 		bail: config.bail, | 
					
						
							|  |  |  | 		cache: optionalNestedConfig(config.cache, cache => { | 
					
						
							|  |  |  | 			if (cache === false) return false; | 
					
						
							|  |  |  | 			if (cache === true) { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					type: "memory" | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			switch (cache.type) { | 
					
						
							|  |  |  | 				case "filesystem": | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						type: "filesystem", | 
					
						
							|  |  |  | 						buildDependencies: nestedConfig( | 
					
						
							|  |  |  | 							cache.buildDependencies, | 
					
						
							|  |  |  | 							buildDependencies => ({ | 
					
						
							|  |  |  | 								...buildDependencies | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						), | 
					
						
							|  |  |  | 						cacheDirectory: cache.cacheDirectory, | 
					
						
							|  |  |  | 						cacheLocation: cache.cacheLocation, | 
					
						
							|  |  |  | 						hashAlgorithm: cache.hashAlgorithm, | 
					
						
							|  |  |  | 						idleTimeout: cache.idleTimeout, | 
					
						
							|  |  |  | 						idleTimeoutForInitialStore: cache.idleTimeoutForInitialStore, | 
					
						
							|  |  |  | 						immutablePaths: optionalNestedArray(cache.immutablePaths, p => [ | 
					
						
							|  |  |  | 							...p | 
					
						
							|  |  |  | 						]), | 
					
						
							|  |  |  | 						managedPaths: optionalNestedArray(cache.managedPaths, p => [...p]), | 
					
						
							|  |  |  | 						name: cache.name, | 
					
						
							|  |  |  | 						store: cache.store, | 
					
						
							|  |  |  | 						version: cache.version | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				case undefined: | 
					
						
							|  |  |  | 				case "memory": | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						type: "memory", | 
					
						
							|  |  |  | 						immutablePaths: optionalNestedArray(cache.immutablePaths, p => [ | 
					
						
							|  |  |  | 							...p | 
					
						
							|  |  |  | 						]), | 
					
						
							|  |  |  | 						managedPaths: optionalNestedArray(cache.managedPaths, p => [...p]) | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				default: | 
					
						
							| 
									
										
										
										
											2020-03-30 23:56:37 +08:00
										 |  |  | 					// @ts-expect-error Property 'type' does not exist on type 'never'. ts(2339)
 | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 					throw new Error(`Not implemented cache.type ${cache.type}`); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 		context: config.context, | 
					
						
							|  |  |  | 		dependencies: config.dependencies, | 
					
						
							|  |  |  | 		devServer: optionalNestedConfig(config.devServer, devServer => ({ | 
					
						
							|  |  |  | 			...devServer | 
					
						
							|  |  |  | 		})), | 
					
						
							|  |  |  | 		devtool: config.devtool, | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 		entry: | 
					
						
							|  |  |  | 			config.entry === undefined | 
					
						
							|  |  |  | 				? { main: {} } | 
					
						
							|  |  |  | 				: typeof config.entry === "function" | 
					
						
							|  |  |  | 				? (fn => () => | 
					
						
							|  |  |  | 						Promise.resolve().then(fn).then(getNormalizedEntryStatic))( | 
					
						
							|  |  |  | 						config.entry | 
					
						
							|  |  |  | 				  ) | 
					
						
							|  |  |  | 				: getNormalizedEntryStatic(config.entry), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		experiments: nestedConfig(config.experiments, experiments => ({ | 
					
						
							|  |  |  | 			...experiments | 
					
						
							|  |  |  | 		})), | 
					
						
							|  |  |  | 		externals: config.externals, | 
					
						
							| 
									
										
										
										
											2020-07-17 23:58:45 +08:00
										 |  |  | 		externalsType: config.externalsType, | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		infrastructureLogging: nestedConfig( | 
					
						
							|  |  |  | 			config.infrastructureLogging, | 
					
						
							|  |  |  | 			infrastructureLogging => ({ | 
					
						
							|  |  |  | 				...infrastructureLogging | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		), | 
					
						
							|  |  |  | 		loader: config.loader, | 
					
						
							|  |  |  | 		mode: config.mode, | 
					
						
							|  |  |  | 		module: nestedConfig(config.module, module => ({ | 
					
						
							|  |  |  | 			...module, | 
					
						
							|  |  |  | 			rules: nestedArray(module.rules, r => [...r]) | 
					
						
							|  |  |  | 		})), | 
					
						
							|  |  |  | 		name: config.name, | 
					
						
							|  |  |  | 		node: nestedConfig( | 
					
						
							|  |  |  | 			config.node, | 
					
						
							|  |  |  | 			node => | 
					
						
							|  |  |  | 				node && { | 
					
						
							|  |  |  | 					...node | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 		), | 
					
						
							| 
									
										
										
										
											2020-07-17 21:39:16 +08:00
										 |  |  | 		optimization: nestedConfig(config.optimization, optimization => { | 
					
						
							|  |  |  | 			return { | 
					
						
							|  |  |  | 				...optimization, | 
					
						
							|  |  |  | 				runtimeChunk: getNormalizedOptimizationRuntimeChunk( | 
					
						
							|  |  |  | 					optimization.runtimeChunk | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				splitChunks: nestedConfig( | 
					
						
							|  |  |  | 					optimization.splitChunks, | 
					
						
							|  |  |  | 					splitChunks => | 
					
						
							|  |  |  | 						splitChunks && { | 
					
						
							|  |  |  | 							...splitChunks, | 
					
						
							|  |  |  | 							cacheGroups: nestedConfig( | 
					
						
							|  |  |  | 								splitChunks.cacheGroups, | 
					
						
							|  |  |  | 								cacheGroups => ({ | 
					
						
							|  |  |  | 									...cacheGroups | 
					
						
							|  |  |  | 								}) | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				emitOnErrors: | 
					
						
							|  |  |  | 					optimization.noEmitOnErrors !== undefined | 
					
						
							|  |  |  | 						? handledDeprecatedNoEmitOnErrors( | 
					
						
							|  |  |  | 								optimization.noEmitOnErrors, | 
					
						
							|  |  |  | 								optimization.emitOnErrors | 
					
						
							|  |  |  | 						  ) | 
					
						
							|  |  |  | 						: optimization.emitOnErrors | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 		output: nestedConfig(config.output, output => { | 
					
						
							| 
									
										
										
										
											2020-02-27 00:20:50 +08:00
										 |  |  | 			const { library } = output; | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 			const libraryAsName = /** @type {LibraryName} */ (library); | 
					
						
							|  |  |  | 			const libraryBase = | 
					
						
							|  |  |  | 				typeof library === "object" && | 
					
						
							|  |  |  | 				library && | 
					
						
							|  |  |  | 				!Array.isArray(library) && | 
					
						
							|  |  |  | 				"type" in library | 
					
						
							|  |  |  | 					? library | 
					
						
							|  |  |  | 					: libraryAsName || output.libraryTarget | 
					
						
							|  |  |  | 					? /** @type {LibraryOptions} */ ({ | 
					
						
							|  |  |  | 							type: "var", | 
					
						
							|  |  |  | 							name: libraryAsName | 
					
						
							|  |  |  | 					  }) | 
					
						
							|  |  |  | 					: undefined; | 
					
						
							|  |  |  | 			/** @type {OutputNormalized} */ | 
					
						
							|  |  |  | 			const result = { | 
					
						
							|  |  |  | 				assetModuleFilename: output.assetModuleFilename, | 
					
						
							|  |  |  | 				chunkCallbackName: output.chunkCallbackName, | 
					
						
							|  |  |  | 				chunkFilename: output.chunkFilename, | 
					
						
							|  |  |  | 				chunkLoadTimeout: output.chunkLoadTimeout, | 
					
						
							|  |  |  | 				compareBeforeEmit: output.compareBeforeEmit, | 
					
						
							|  |  |  | 				crossOriginLoading: output.crossOriginLoading, | 
					
						
							|  |  |  | 				devtoolFallbackModuleFilenameTemplate: | 
					
						
							|  |  |  | 					output.devtoolFallbackModuleFilenameTemplate, | 
					
						
							|  |  |  | 				devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate, | 
					
						
							|  |  |  | 				devtoolNamespace: output.devtoolNamespace, | 
					
						
							|  |  |  | 				ecmaVersion: normalizeEcmaVersion(output.ecmaVersion), | 
					
						
							|  |  |  | 				enabledLibraryTypes: nestedArray(output.enabledLibraryTypes, t => [ | 
					
						
							|  |  |  | 					...t | 
					
						
							|  |  |  | 				]), | 
					
						
							|  |  |  | 				filename: output.filename, | 
					
						
							|  |  |  | 				globalObject: output.globalObject, | 
					
						
							|  |  |  | 				hashDigest: output.hashDigest, | 
					
						
							|  |  |  | 				hashDigestLength: output.hashDigestLength, | 
					
						
							|  |  |  | 				hashFunction: output.hashFunction, | 
					
						
							|  |  |  | 				hashSalt: output.hashSalt, | 
					
						
							|  |  |  | 				hotUpdateChunkFilename: output.hotUpdateChunkFilename, | 
					
						
							|  |  |  | 				hotUpdateFunction: output.hotUpdateFunction, | 
					
						
							|  |  |  | 				hotUpdateMainFilename: output.hotUpdateMainFilename, | 
					
						
							|  |  |  | 				iife: output.iife, | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 				importFunctionName: output.importFunctionName, | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				jsonpFunction: output.jsonpFunction, | 
					
						
							| 
									
										
										
										
											2020-06-25 04:05:21 +08:00
										 |  |  | 				scriptType: output.scriptType, | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				library: libraryBase && { | 
					
						
							|  |  |  | 					type: | 
					
						
							|  |  |  | 						output.libraryTarget !== undefined | 
					
						
							|  |  |  | 							? output.libraryTarget | 
					
						
							|  |  |  | 							: libraryBase.type, | 
					
						
							|  |  |  | 					auxiliaryComment: | 
					
						
							|  |  |  | 						output.auxiliaryComment !== undefined | 
					
						
							|  |  |  | 							? output.auxiliaryComment | 
					
						
							|  |  |  | 							: libraryBase.auxiliaryComment, | 
					
						
							|  |  |  | 					export: | 
					
						
							|  |  |  | 						output.libraryExport !== undefined | 
					
						
							|  |  |  | 							? output.libraryExport | 
					
						
							|  |  |  | 							: libraryBase.export, | 
					
						
							|  |  |  | 					name: libraryBase.name, | 
					
						
							|  |  |  | 					umdNamedDefine: | 
					
						
							|  |  |  | 						output.umdNamedDefine !== undefined | 
					
						
							|  |  |  | 							? output.umdNamedDefine | 
					
						
							|  |  |  | 							: libraryBase.umdNamedDefine | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				module: output.module, | 
					
						
							|  |  |  | 				path: output.path, | 
					
						
							|  |  |  | 				pathinfo: output.pathinfo, | 
					
						
							|  |  |  | 				publicPath: output.publicPath, | 
					
						
							|  |  |  | 				sourceMapFilename: output.sourceMapFilename, | 
					
						
							|  |  |  | 				sourcePrefix: output.sourcePrefix, | 
					
						
							|  |  |  | 				strictModuleExceptionHandling: output.strictModuleExceptionHandling, | 
					
						
							|  |  |  | 				uniqueName: output.uniqueName, | 
					
						
							|  |  |  | 				webassemblyModuleFilename: output.webassemblyModuleFilename | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			return result; | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		parallelism: config.parallelism, | 
					
						
							|  |  |  | 		performance: optionalNestedConfig(config.performance, performance => { | 
					
						
							|  |  |  | 			if (performance === false) return false; | 
					
						
							|  |  |  | 			return { | 
					
						
							|  |  |  | 				...performance | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 		plugins: nestedArray(config.plugins, p => [...p]), | 
					
						
							|  |  |  | 		profile: config.profile, | 
					
						
							|  |  |  | 		recordsInputPath: | 
					
						
							|  |  |  | 			config.recordsInputPath !== undefined | 
					
						
							|  |  |  | 				? config.recordsInputPath | 
					
						
							|  |  |  | 				: config.recordsPath, | 
					
						
							|  |  |  | 		recordsOutputPath: | 
					
						
							|  |  |  | 			config.recordsOutputPath !== undefined | 
					
						
							|  |  |  | 				? config.recordsOutputPath | 
					
						
							|  |  |  | 				: config.recordsPath, | 
					
						
							|  |  |  | 		resolve: nestedConfig(config.resolve, resolve => ({ | 
					
						
							| 
									
										
										
										
											2020-05-28 22:52:30 +08:00
										 |  |  | 			...resolve, | 
					
						
							|  |  |  | 			byDependency: keyedNestedConfig(resolve.byDependency, resolve => ({ | 
					
						
							|  |  |  | 				...resolve | 
					
						
							|  |  |  | 			})) | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		})), | 
					
						
							|  |  |  | 		resolveLoader: nestedConfig(config.resolveLoader, resolve => ({ | 
					
						
							|  |  |  | 			...resolve | 
					
						
							|  |  |  | 		})), | 
					
						
							|  |  |  | 		stats: nestedConfig(config.stats, stats => { | 
					
						
							|  |  |  | 			if (stats === false) { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					preset: "none" | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (stats === true) { | 
					
						
							| 
									
										
										
										
											2020-06-25 10:41:17 +08:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					preset: "normal" | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (typeof stats === "string") { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					preset: stats | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return { | 
					
						
							|  |  |  | 				...stats | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 		target: config.target, | 
					
						
							|  |  |  | 		watch: config.watch, | 
					
						
							|  |  |  | 		watchOptions: nestedConfig(config.watchOptions, watchOptions => ({ | 
					
						
							|  |  |  | 			...watchOptions | 
					
						
							|  |  |  | 		})) | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {EntryStatic} entry static entry options | 
					
						
							|  |  |  |  * @returns {EntryStaticNormalized} normalized static entry options | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getNormalizedEntryStatic = entry => { | 
					
						
							|  |  |  | 	if (typeof entry === "string") { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			main: { | 
					
						
							|  |  |  | 				import: [entry] | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (Array.isArray(entry)) { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			main: { | 
					
						
							|  |  |  | 				import: entry | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/** @type {EntryStaticNormalized} */ | 
					
						
							|  |  |  | 	const result = {}; | 
					
						
							|  |  |  | 	for (const key of Object.keys(entry)) { | 
					
						
							|  |  |  | 		const value = entry[key]; | 
					
						
							|  |  |  | 		if (typeof value === "string") { | 
					
						
							|  |  |  | 			result[key] = { | 
					
						
							|  |  |  | 				import: [value] | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} else if (Array.isArray(value)) { | 
					
						
							|  |  |  | 			result[key] = { | 
					
						
							|  |  |  | 				import: value | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 			result[key] = { | 
					
						
							|  |  |  | 				import: | 
					
						
							|  |  |  | 					value.import && | 
					
						
							|  |  |  | 					(Array.isArray(value.import) ? value.import : [value.import]), | 
					
						
							|  |  |  | 				filename: value.filename, | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | 				runtime: value.runtime, | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 				dependOn: | 
					
						
							|  |  |  | 					value.dependOn && | 
					
						
							| 
									
										
										
										
											2020-02-26 19:34:57 +08:00
										 |  |  | 					(Array.isArray(value.dependOn) ? value.dependOn : [value.dependOn]), | 
					
						
							|  |  |  | 				library: value.library | 
					
						
							| 
									
										
										
										
											2020-02-26 20:08:05 +08:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {OptimizationRuntimeChunk=} runtimeChunk runtimeChunk option | 
					
						
							|  |  |  |  * @returns {OptimizationRuntimeChunkNormalized=} normalized runtimeChunk option | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getNormalizedOptimizationRuntimeChunk = runtimeChunk => { | 
					
						
							|  |  |  | 	if (runtimeChunk === undefined) return undefined; | 
					
						
							|  |  |  | 	if (runtimeChunk === false) return false; | 
					
						
							|  |  |  | 	if (runtimeChunk === "single") { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			name: () => "runtime" | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (runtimeChunk === true || runtimeChunk === "multiple") { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			name: entrypoint => `runtime~${entrypoint.name}` | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	const { name } = runtimeChunk; | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		name: typeof name === "function" ? name : () => name | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.getNormalizedWebpackOptions = getNormalizedWebpackOptions; |