| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | /** @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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @param {T|undefined} value value or not | 
					
						
							|  |  |  |  * @returns {T} result value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const cloneObject = value => { | 
					
						
							|  |  |  | 	return /** @type {T} */ ({ ...value }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  |  * @param {Record<string, function(T): R>=} customKeys custom nested handler for some keys | 
					
						
							| 
									
										
										
										
											2020-05-28 22:52:30 +08:00
										 |  |  |  * @returns {Record<string, R>} result value | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | const keyedNestedConfig = (value, fn, customKeys) => { | 
					
						
							|  |  |  | 	const result = | 
					
						
							|  |  |  | 		value === undefined | 
					
						
							|  |  |  | 			? {} | 
					
						
							|  |  |  | 			: Object.keys(value).reduce( | 
					
						
							|  |  |  | 					(obj, key) => ( | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 						(obj[key] = ( | 
					
						
							|  |  |  | 							customKeys && key in customKeys ? customKeys[key] : fn | 
					
						
							|  |  |  | 						)(value[key])), | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 						obj | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 					/** @type {Record<string, R>} */ ({}) | 
					
						
							|  |  |  | 			  ); | 
					
						
							|  |  |  | 	if (customKeys) { | 
					
						
							|  |  |  | 		for (const key of Object.keys(customKeys)) { | 
					
						
							|  |  |  | 			if (!(key in result)) { | 
					
						
							|  |  |  | 				result[key] = customKeys[key](/** @type {T} */ ({})); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-05-28 22:52:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 { | 
					
						
							| 
									
										
										
										
											2021-04-01 22:59:00 +08:00
										 |  |  | 					type: "memory", | 
					
						
							|  |  |  | 					maxGenerations: undefined | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			switch (cache.type) { | 
					
						
							|  |  |  | 				case "filesystem": | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						type: "filesystem", | 
					
						
							| 
									
										
										
										
											2021-06-02 02:02:19 +08:00
										 |  |  | 						allowCollectingMemory: cache.allowCollectingMemory, | 
					
						
							| 
									
										
										
										
											2021-04-01 22:59:00 +08:00
										 |  |  | 						maxMemoryGenerations: cache.maxMemoryGenerations, | 
					
						
							|  |  |  | 						maxAge: cache.maxAge, | 
					
						
							| 
									
										
										
										
											2021-04-27 17:06:01 +08:00
										 |  |  | 						profile: cache.profile, | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 						buildDependencies: cloneObject(cache.buildDependencies), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 						cacheDirectory: cache.cacheDirectory, | 
					
						
							|  |  |  | 						cacheLocation: cache.cacheLocation, | 
					
						
							|  |  |  | 						hashAlgorithm: cache.hashAlgorithm, | 
					
						
							| 
									
										
										
										
											2021-06-30 06:05:38 +08:00
										 |  |  | 						compression: cache.compression, | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 						idleTimeout: cache.idleTimeout, | 
					
						
							|  |  |  | 						idleTimeoutForInitialStore: cache.idleTimeoutForInitialStore, | 
					
						
							| 
									
										
										
										
											2021-06-28 17:35:14 +08:00
										 |  |  | 						idleTimeoutAfterLargeChanges: cache.idleTimeoutAfterLargeChanges, | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 						name: cache.name, | 
					
						
							|  |  |  | 						store: cache.store, | 
					
						
							|  |  |  | 						version: cache.version | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				case undefined: | 
					
						
							|  |  |  | 				case "memory": | 
					
						
							|  |  |  | 					return { | 
					
						
							| 
									
										
										
										
											2021-04-01 22:59:00 +08:00
										 |  |  | 						type: "memory", | 
					
						
							|  |  |  | 						maxGenerations: cache.maxGenerations | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 					}; | 
					
						
							|  |  |  | 				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" | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 				? ( | 
					
						
							|  |  |  | 						fn => () => | 
					
						
							|  |  |  | 							Promise.resolve().then(fn).then(getNormalizedEntryStatic) | 
					
						
							|  |  |  | 				  )(config.entry) | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 				: getNormalizedEntryStatic(config.entry), | 
					
						
							| 
									
										
										
										
											2021-08-04 21:55:58 +08:00
										 |  |  | 		experiments: nestedConfig(config.experiments, experiments => ({ | 
					
						
							|  |  |  | 			...experiments, | 
					
						
							|  |  |  | 			buildHttp: optionalNestedConfig(experiments.buildHttp, options => | 
					
						
							| 
									
										
										
										
											2021-10-19 01:23:29 +08:00
										 |  |  | 				Array.isArray(options) ? { allowedUris: options } : options | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			lazyCompilation: optionalNestedConfig( | 
					
						
							|  |  |  | 				experiments.lazyCompilation, | 
					
						
							|  |  |  | 				options => | 
					
						
							|  |  |  | 					options === true ? {} : options === false ? undefined : options | 
					
						
							| 
									
										
										
										
											2022-01-19 01:14:50 +08:00
										 |  |  | 			), | 
					
						
							|  |  |  | 			css: optionalNestedConfig(experiments.css, options => | 
					
						
							|  |  |  | 				options === true ? {} : options === false ? undefined : options | 
					
						
							| 
									
										
										
										
											2021-08-04 21:55:58 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 		})), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		externals: config.externals, | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 		externalsPresets: cloneObject(config.externalsPresets), | 
					
						
							| 
									
										
										
										
											2020-07-17 23:58:45 +08:00
										 |  |  | 		externalsType: config.externalsType, | 
					
						
							| 
									
										
										
										
											2020-09-21 04:08:38 +08:00
										 |  |  | 		ignoreWarnings: config.ignoreWarnings | 
					
						
							|  |  |  | 			? config.ignoreWarnings.map(ignore => { | 
					
						
							|  |  |  | 					if (typeof ignore === "function") return ignore; | 
					
						
							|  |  |  | 					const i = ignore instanceof RegExp ? { message: ignore } : ignore; | 
					
						
							|  |  |  | 					return (warning, { requestShortener }) => { | 
					
						
							|  |  |  | 						if (!i.message && !i.module && !i.file) return false; | 
					
						
							|  |  |  | 						if (i.message && !i.message.test(warning.message)) { | 
					
						
							|  |  |  | 							return false; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if ( | 
					
						
							|  |  |  | 							i.module && | 
					
						
							|  |  |  | 							(!warning.module || | 
					
						
							|  |  |  | 								!i.module.test( | 
					
						
							|  |  |  | 									warning.module.readableIdentifier(requestShortener) | 
					
						
							|  |  |  | 								)) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							return false; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if (i.file && (!warning.file || !i.file.test(warning.file))) { | 
					
						
							|  |  |  | 							return false; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						return true; | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 			  }) | 
					
						
							|  |  |  | 			: undefined, | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 		infrastructureLogging: cloneObject(config.infrastructureLogging), | 
					
						
							|  |  |  | 		loader: cloneObject(config.loader), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		mode: config.mode, | 
					
						
							|  |  |  | 		module: nestedConfig(config.module, module => ({ | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 			noParse: module.noParse, | 
					
						
							|  |  |  | 			unsafeCache: module.unsafeCache, | 
					
						
							|  |  |  | 			parser: keyedNestedConfig(module.parser, cloneObject, { | 
					
						
							|  |  |  | 				javascript: parserOptions => ({ | 
					
						
							|  |  |  | 					unknownContextRequest: module.unknownContextRequest, | 
					
						
							|  |  |  | 					unknownContextRegExp: module.unknownContextRegExp, | 
					
						
							|  |  |  | 					unknownContextRecursive: module.unknownContextRecursive, | 
					
						
							|  |  |  | 					unknownContextCritical: module.unknownContextCritical, | 
					
						
							|  |  |  | 					exprContextRequest: module.exprContextRequest, | 
					
						
							|  |  |  | 					exprContextRegExp: module.exprContextRegExp, | 
					
						
							|  |  |  | 					exprContextRecursive: module.exprContextRecursive, | 
					
						
							|  |  |  | 					exprContextCritical: module.exprContextCritical, | 
					
						
							|  |  |  | 					wrappedContextRegExp: module.wrappedContextRegExp, | 
					
						
							|  |  |  | 					wrappedContextRecursive: module.wrappedContextRecursive, | 
					
						
							|  |  |  | 					wrappedContextCritical: module.wrappedContextCritical, | 
					
						
							| 
									
										
										
										
											2021-11-05 23:13:49 +08:00
										 |  |  | 					// TODO webpack 6 remove
 | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 					strictExportPresence: module.strictExportPresence, | 
					
						
							|  |  |  | 					strictThisContextOnImports: module.strictThisContextOnImports, | 
					
						
							|  |  |  | 					...parserOptions | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			}), | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 			generator: cloneObject(module.generator), | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 			defaultRules: optionalNestedArray(module.defaultRules, r => [...r]), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			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, | 
					
						
							| 
									
										
										
										
											2020-09-29 17:16:24 +08:00
										 |  |  | 							defaultSizeTypes: splitChunks.defaultSizeTypes | 
					
						
							|  |  |  | 								? [...splitChunks.defaultSizeTypes] | 
					
						
							|  |  |  | 								: ["..."], | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 							cacheGroups: cloneObject(splitChunks.cacheGroups) | 
					
						
							| 
									
										
										
										
											2020-07-17 21:39:16 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				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} */ ({ | 
					
						
							|  |  |  | 							name: libraryAsName | 
					
						
							|  |  |  | 					  }) | 
					
						
							|  |  |  | 					: undefined; | 
					
						
							|  |  |  | 			/** @type {OutputNormalized} */ | 
					
						
							|  |  |  | 			const result = { | 
					
						
							|  |  |  | 				assetModuleFilename: output.assetModuleFilename, | 
					
						
							| 
									
										
										
										
											2021-11-10 21:23:03 +08:00
										 |  |  | 				asyncChunks: output.asyncChunks, | 
					
						
							| 
									
										
										
										
											2020-08-18 12:39:16 +08:00
										 |  |  | 				charset: output.charset, | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				chunkFilename: output.chunkFilename, | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 				chunkFormat: output.chunkFormat, | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 				chunkLoading: output.chunkLoading, | 
					
						
							| 
									
										
										
										
											2020-08-25 15:16:49 +08:00
										 |  |  | 				chunkLoadingGlobal: output.chunkLoadingGlobal, | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				chunkLoadTimeout: output.chunkLoadTimeout, | 
					
						
							| 
									
										
										
										
											2022-01-14 19:06:05 +08:00
										 |  |  | 				cssFilename: output.cssFilename, | 
					
						
							|  |  |  | 				cssChunkFilename: output.cssChunkFilename, | 
					
						
							| 
									
										
										
										
											2020-10-07 20:30:14 +08:00
										 |  |  | 				clean: output.clean, | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				compareBeforeEmit: output.compareBeforeEmit, | 
					
						
							|  |  |  | 				crossOriginLoading: output.crossOriginLoading, | 
					
						
							|  |  |  | 				devtoolFallbackModuleFilenameTemplate: | 
					
						
							|  |  |  | 					output.devtoolFallbackModuleFilenameTemplate, | 
					
						
							|  |  |  | 				devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate, | 
					
						
							|  |  |  | 				devtoolNamespace: output.devtoolNamespace, | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 				environment: cloneObject(output.environment), | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 				enabledChunkLoadingTypes: output.enabledChunkLoadingTypes | 
					
						
							|  |  |  | 					? [...output.enabledChunkLoadingTypes] | 
					
						
							|  |  |  | 					: ["..."], | 
					
						
							|  |  |  | 				enabledLibraryTypes: output.enabledLibraryTypes | 
					
						
							|  |  |  | 					? [...output.enabledLibraryTypes] | 
					
						
							|  |  |  | 					: ["..."], | 
					
						
							| 
									
										
										
										
											2020-09-09 15:23:01 +08:00
										 |  |  | 				enabledWasmLoadingTypes: output.enabledWasmLoadingTypes | 
					
						
							|  |  |  | 					? [...output.enabledWasmLoadingTypes] | 
					
						
							|  |  |  | 					: ["..."], | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				filename: output.filename, | 
					
						
							|  |  |  | 				globalObject: output.globalObject, | 
					
						
							|  |  |  | 				hashDigest: output.hashDigest, | 
					
						
							|  |  |  | 				hashDigestLength: output.hashDigestLength, | 
					
						
							|  |  |  | 				hashFunction: output.hashFunction, | 
					
						
							|  |  |  | 				hashSalt: output.hashSalt, | 
					
						
							|  |  |  | 				hotUpdateChunkFilename: output.hotUpdateChunkFilename, | 
					
						
							| 
									
										
										
										
											2020-08-25 15:16:49 +08:00
										 |  |  | 				hotUpdateGlobal: output.hotUpdateGlobal, | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				hotUpdateMainFilename: output.hotUpdateMainFilename, | 
					
						
							|  |  |  | 				iife: output.iife, | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 				importFunctionName: output.importFunctionName, | 
					
						
							| 
									
										
										
										
											2020-09-18 16:55:37 +08:00
										 |  |  | 				importMetaName: output.importMetaName, | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2021-05-10 16:34:21 +08:00
										 |  |  | 				trustedTypes: optionalNestedConfig( | 
					
						
							|  |  |  | 					output.trustedTypes, | 
					
						
							|  |  |  | 					trustedTypes => { | 
					
						
							|  |  |  | 						if (trustedTypes === true) return {}; | 
					
						
							|  |  |  | 						if (typeof trustedTypes === "string") | 
					
						
							|  |  |  | 							return { policyName: trustedTypes }; | 
					
						
							|  |  |  | 						return { ...trustedTypes }; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				), | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 				uniqueName: output.uniqueName, | 
					
						
							| 
									
										
										
										
											2020-09-09 15:23:01 +08:00
										 |  |  | 				wasmLoading: output.wasmLoading, | 
					
						
							|  |  |  | 				webassemblyModuleFilename: output.webassemblyModuleFilename, | 
					
						
							|  |  |  | 				workerChunkLoading: output.workerChunkLoading, | 
					
						
							|  |  |  | 				workerWasmLoading: output.workerWasmLoading | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 			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, | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 			byDependency: keyedNestedConfig(resolve.byDependency, cloneObject) | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		})), | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 		resolveLoader: cloneObject(config.resolveLoader), | 
					
						
							| 
									
										
										
										
											2020-08-26 06:36:16 +08:00
										 |  |  | 		snapshot: nestedConfig(config.snapshot, snapshot => ({ | 
					
						
							|  |  |  | 			resolveBuildDependencies: optionalNestedConfig( | 
					
						
							|  |  |  | 				snapshot.resolveBuildDependencies, | 
					
						
							|  |  |  | 				resolveBuildDependencies => ({ | 
					
						
							|  |  |  | 					timestamp: resolveBuildDependencies.timestamp, | 
					
						
							|  |  |  | 					hash: resolveBuildDependencies.hash | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			buildDependencies: optionalNestedConfig( | 
					
						
							|  |  |  | 				snapshot.buildDependencies, | 
					
						
							|  |  |  | 				buildDependencies => ({ | 
					
						
							|  |  |  | 					timestamp: buildDependencies.timestamp, | 
					
						
							|  |  |  | 					hash: buildDependencies.hash | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			resolve: optionalNestedConfig(snapshot.resolve, resolve => ({ | 
					
						
							|  |  |  | 				timestamp: resolve.timestamp, | 
					
						
							|  |  |  | 				hash: resolve.hash | 
					
						
							|  |  |  | 			})), | 
					
						
							|  |  |  | 			module: optionalNestedConfig(snapshot.module, module => ({ | 
					
						
							|  |  |  | 				timestamp: module.timestamp, | 
					
						
							|  |  |  | 				hash: module.hash | 
					
						
							|  |  |  | 			})), | 
					
						
							|  |  |  | 			immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]), | 
					
						
							|  |  |  | 			managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]) | 
					
						
							|  |  |  | 		})), | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | 		watchOptions: cloneObject(config.watchOptions) | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @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-12-22 21:51:09 +08:00
										 |  |  | 				layer: value.layer, | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | 				runtime: value.runtime, | 
					
						
							| 
									
										
										
										
											2022-02-21 21:23:47 +08:00
										 |  |  | 				baseUri: value.baseUri, | 
					
						
							| 
									
										
										
										
											2021-04-14 22:38:01 +08:00
										 |  |  | 				publicPath: value.publicPath, | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 				chunkLoading: value.chunkLoading, | 
					
						
							| 
									
										
										
										
											2021-11-10 21:23:03 +08:00
										 |  |  | 				asyncChunks: value.asyncChunks, | 
					
						
							| 
									
										
										
										
											2020-09-09 15:23:01 +08:00
										 |  |  | 				wasmLoading: value.wasmLoading, | 
					
						
							| 
									
										
										
										
											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; |