[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const util = require("util");
|
---|
| 9 |
|
---|
| 10 | /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
|
---|
| 11 | /** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
|
---|
| 12 | /** @typedef {import("../../declarations/WebpackOptions").EntryStatic} EntryStatic */
|
---|
| 13 | /** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
|
---|
| 14 | /** @typedef {import("../../declarations/WebpackOptions").Externals} Externals */
|
---|
| 15 | /** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
|
---|
| 16 | /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
---|
| 17 | /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptionsNormalized */
|
---|
| 18 | /** @typedef {import("../../declarations/WebpackOptions").OptimizationRuntimeChunk} OptimizationRuntimeChunk */
|
---|
| 19 | /** @typedef {import("../../declarations/WebpackOptions").OptimizationRuntimeChunkNormalized} OptimizationRuntimeChunkNormalized */
|
---|
| 20 | /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
|
---|
| 21 | /** @typedef {import("../../declarations/WebpackOptions").Plugins} Plugins */
|
---|
| 22 | /** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
|
---|
| 23 | /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
|
---|
| 24 | /** @typedef {import("../Entrypoint")} Entrypoint */
|
---|
| 25 |
|
---|
| 26 | const handledDeprecatedNoEmitOnErrors = util.deprecate(
|
---|
| 27 | /**
|
---|
| 28 | * @param {boolean} noEmitOnErrors no emit on errors
|
---|
| 29 | * @param {boolean | undefined} emitOnErrors emit on errors
|
---|
| 30 | * @returns {boolean} emit on errors
|
---|
| 31 | */
|
---|
| 32 | (noEmitOnErrors, emitOnErrors) => {
|
---|
| 33 | if (emitOnErrors !== undefined && !noEmitOnErrors === !emitOnErrors) {
|
---|
| 34 | throw new Error(
|
---|
| 35 | "Conflicting use of 'optimization.noEmitOnErrors' and 'optimization.emitOnErrors'. Remove deprecated 'optimization.noEmitOnErrors' from config."
|
---|
| 36 | );
|
---|
| 37 | }
|
---|
| 38 | return !noEmitOnErrors;
|
---|
| 39 | },
|
---|
| 40 | "optimization.noEmitOnErrors is deprecated in favor of optimization.emitOnErrors",
|
---|
| 41 | "DEP_WEBPACK_CONFIGURATION_OPTIMIZATION_NO_EMIT_ON_ERRORS"
|
---|
| 42 | );
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * @template T
|
---|
| 46 | * @template R
|
---|
| 47 | * @param {T|undefined} value value or not
|
---|
| 48 | * @param {function(T): R} fn nested handler
|
---|
| 49 | * @returns {R} result value
|
---|
| 50 | */
|
---|
| 51 | const nestedConfig = (value, fn) =>
|
---|
| 52 | value === undefined ? fn(/** @type {T} */ ({})) : fn(value);
|
---|
| 53 |
|
---|
| 54 | /**
|
---|
| 55 | * @template T
|
---|
| 56 | * @param {T|undefined} value value or not
|
---|
| 57 | * @returns {T} result value
|
---|
| 58 | */
|
---|
| 59 | const cloneObject = value => /** @type {T} */ ({ ...value });
|
---|
| 60 | /**
|
---|
| 61 | * @template T
|
---|
| 62 | * @template R
|
---|
| 63 | * @param {T|undefined} value value or not
|
---|
| 64 | * @param {function(T): R} fn nested handler
|
---|
| 65 | * @returns {R|undefined} result value
|
---|
| 66 | */
|
---|
| 67 | const optionalNestedConfig = (value, fn) =>
|
---|
| 68 | value === undefined ? undefined : fn(value);
|
---|
| 69 |
|
---|
| 70 | /**
|
---|
| 71 | * @template T
|
---|
| 72 | * @template R
|
---|
| 73 | * @param {T[]|undefined} value array or not
|
---|
| 74 | * @param {function(T[]): R[]} fn nested handler
|
---|
| 75 | * @returns {R[]|undefined} cloned value
|
---|
| 76 | */
|
---|
| 77 | const nestedArray = (value, fn) => (Array.isArray(value) ? fn(value) : fn([]));
|
---|
| 78 |
|
---|
| 79 | /**
|
---|
| 80 | * @template T
|
---|
| 81 | * @template R
|
---|
| 82 | * @param {T[]|undefined} value array or not
|
---|
| 83 | * @param {function(T[]): R[]} fn nested handler
|
---|
| 84 | * @returns {R[]|undefined} cloned value
|
---|
| 85 | */
|
---|
| 86 | const optionalNestedArray = (value, fn) =>
|
---|
| 87 | Array.isArray(value) ? fn(value) : undefined;
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * @template T
|
---|
| 91 | * @template R
|
---|
| 92 | * @param {Record<string, T>|undefined} value value or not
|
---|
| 93 | * @param {function(T): R} fn nested handler
|
---|
| 94 | * @param {Record<string, function(T): R>=} customKeys custom nested handler for some keys
|
---|
| 95 | * @returns {Record<string, R>} result value
|
---|
| 96 | */
|
---|
| 97 | const keyedNestedConfig = (value, fn, customKeys) => {
|
---|
| 98 | /* eslint-disable no-sequences */
|
---|
| 99 | const result =
|
---|
| 100 | value === undefined
|
---|
| 101 | ? {}
|
---|
| 102 | : Object.keys(value).reduce(
|
---|
| 103 | (obj, key) => (
|
---|
| 104 | (obj[key] = (
|
---|
| 105 | customKeys && key in customKeys ? customKeys[key] : fn
|
---|
| 106 | )(value[key])),
|
---|
| 107 | obj
|
---|
| 108 | ),
|
---|
| 109 | /** @type {Record<string, R>} */ ({})
|
---|
| 110 | );
|
---|
| 111 | /* eslint-enable no-sequences */
|
---|
| 112 | if (customKeys) {
|
---|
| 113 | for (const key of Object.keys(customKeys)) {
|
---|
| 114 | if (!(key in result)) {
|
---|
| 115 | result[key] = customKeys[key](/** @type {T} */ ({}));
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | return result;
|
---|
| 120 | };
|
---|
| 121 |
|
---|
| 122 | /**
|
---|
| 123 | * @param {WebpackOptions} config input config
|
---|
| 124 | * @returns {WebpackOptionsNormalized} normalized options
|
---|
| 125 | */
|
---|
| 126 | const getNormalizedWebpackOptions = config => ({
|
---|
| 127 | amd: config.amd,
|
---|
| 128 | bail: config.bail,
|
---|
| 129 | cache:
|
---|
| 130 | /** @type {NonNullable<CacheOptions>} */
|
---|
| 131 | (
|
---|
| 132 | optionalNestedConfig(config.cache, cache => {
|
---|
| 133 | if (cache === false) return false;
|
---|
| 134 | if (cache === true) {
|
---|
| 135 | return {
|
---|
| 136 | type: "memory",
|
---|
| 137 | maxGenerations: undefined
|
---|
| 138 | };
|
---|
| 139 | }
|
---|
| 140 | switch (cache.type) {
|
---|
| 141 | case "filesystem":
|
---|
| 142 | return {
|
---|
| 143 | type: "filesystem",
|
---|
| 144 | allowCollectingMemory: cache.allowCollectingMemory,
|
---|
| 145 | maxMemoryGenerations: cache.maxMemoryGenerations,
|
---|
| 146 | maxAge: cache.maxAge,
|
---|
| 147 | profile: cache.profile,
|
---|
| 148 | buildDependencies: cloneObject(cache.buildDependencies),
|
---|
| 149 | cacheDirectory: cache.cacheDirectory,
|
---|
| 150 | cacheLocation: cache.cacheLocation,
|
---|
| 151 | hashAlgorithm: cache.hashAlgorithm,
|
---|
| 152 | compression: cache.compression,
|
---|
| 153 | idleTimeout: cache.idleTimeout,
|
---|
| 154 | idleTimeoutForInitialStore: cache.idleTimeoutForInitialStore,
|
---|
| 155 | idleTimeoutAfterLargeChanges: cache.idleTimeoutAfterLargeChanges,
|
---|
| 156 | name: cache.name,
|
---|
| 157 | store: cache.store,
|
---|
| 158 | version: cache.version,
|
---|
| 159 | readonly: cache.readonly
|
---|
| 160 | };
|
---|
| 161 | case undefined:
|
---|
| 162 | case "memory":
|
---|
| 163 | return {
|
---|
| 164 | type: "memory",
|
---|
| 165 | maxGenerations: cache.maxGenerations
|
---|
| 166 | };
|
---|
| 167 | default:
|
---|
| 168 | // @ts-expect-error Property 'type' does not exist on type 'never'. ts(2339)
|
---|
| 169 | throw new Error(`Not implemented cache.type ${cache.type}`);
|
---|
| 170 | }
|
---|
| 171 | })
|
---|
| 172 | ),
|
---|
| 173 | context: config.context,
|
---|
| 174 | dependencies: config.dependencies,
|
---|
| 175 | devServer: optionalNestedConfig(config.devServer, devServer => {
|
---|
| 176 | if (devServer === false) return false;
|
---|
| 177 | return { ...devServer };
|
---|
| 178 | }),
|
---|
| 179 | devtool: config.devtool,
|
---|
| 180 | entry:
|
---|
| 181 | config.entry === undefined
|
---|
| 182 | ? { main: {} }
|
---|
| 183 | : typeof config.entry === "function"
|
---|
| 184 | ? (
|
---|
| 185 | fn => () =>
|
---|
| 186 | Promise.resolve().then(fn).then(getNormalizedEntryStatic)
|
---|
| 187 | )(config.entry)
|
---|
| 188 | : getNormalizedEntryStatic(config.entry),
|
---|
| 189 | experiments: nestedConfig(config.experiments, experiments => ({
|
---|
| 190 | ...experiments,
|
---|
| 191 | buildHttp: optionalNestedConfig(experiments.buildHttp, options =>
|
---|
| 192 | Array.isArray(options) ? { allowedUris: options } : options
|
---|
| 193 | ),
|
---|
| 194 | lazyCompilation: optionalNestedConfig(
|
---|
| 195 | experiments.lazyCompilation,
|
---|
| 196 | options => (options === true ? {} : options)
|
---|
| 197 | )
|
---|
| 198 | })),
|
---|
| 199 | externals: /** @type {NonNullable<Externals>} */ (config.externals),
|
---|
| 200 | externalsPresets: cloneObject(config.externalsPresets),
|
---|
| 201 | externalsType: config.externalsType,
|
---|
| 202 | ignoreWarnings: config.ignoreWarnings
|
---|
| 203 | ? config.ignoreWarnings.map(ignore => {
|
---|
| 204 | if (typeof ignore === "function") return ignore;
|
---|
| 205 | const i = ignore instanceof RegExp ? { message: ignore } : ignore;
|
---|
| 206 | return (warning, { requestShortener }) => {
|
---|
| 207 | if (!i.message && !i.module && !i.file) return false;
|
---|
| 208 | if (i.message && !i.message.test(warning.message)) {
|
---|
| 209 | return false;
|
---|
| 210 | }
|
---|
| 211 | if (
|
---|
| 212 | i.module &&
|
---|
| 213 | (!warning.module ||
|
---|
| 214 | !i.module.test(
|
---|
| 215 | warning.module.readableIdentifier(requestShortener)
|
---|
| 216 | ))
|
---|
| 217 | ) {
|
---|
| 218 | return false;
|
---|
| 219 | }
|
---|
| 220 | if (i.file && (!warning.file || !i.file.test(warning.file))) {
|
---|
| 221 | return false;
|
---|
| 222 | }
|
---|
| 223 | return true;
|
---|
| 224 | };
|
---|
| 225 | })
|
---|
| 226 | : undefined,
|
---|
| 227 | infrastructureLogging: cloneObject(config.infrastructureLogging),
|
---|
| 228 | loader: cloneObject(config.loader),
|
---|
| 229 | mode: config.mode,
|
---|
| 230 | module:
|
---|
| 231 | /** @type {ModuleOptionsNormalized} */
|
---|
| 232 | (
|
---|
| 233 | nestedConfig(config.module, module => ({
|
---|
| 234 | noParse: module.noParse,
|
---|
| 235 | unsafeCache: module.unsafeCache,
|
---|
| 236 | parser: keyedNestedConfig(module.parser, cloneObject, {
|
---|
| 237 | javascript: parserOptions => ({
|
---|
| 238 | unknownContextRequest: module.unknownContextRequest,
|
---|
| 239 | unknownContextRegExp: module.unknownContextRegExp,
|
---|
| 240 | unknownContextRecursive: module.unknownContextRecursive,
|
---|
| 241 | unknownContextCritical: module.unknownContextCritical,
|
---|
| 242 | exprContextRequest: module.exprContextRequest,
|
---|
| 243 | exprContextRegExp: module.exprContextRegExp,
|
---|
| 244 | exprContextRecursive: module.exprContextRecursive,
|
---|
| 245 | exprContextCritical: module.exprContextCritical,
|
---|
| 246 | wrappedContextRegExp: module.wrappedContextRegExp,
|
---|
| 247 | wrappedContextRecursive: module.wrappedContextRecursive,
|
---|
| 248 | wrappedContextCritical: module.wrappedContextCritical,
|
---|
| 249 | // TODO webpack 6 remove
|
---|
| 250 | strictExportPresence: module.strictExportPresence,
|
---|
| 251 | strictThisContextOnImports: module.strictThisContextOnImports,
|
---|
| 252 | ...parserOptions
|
---|
| 253 | })
|
---|
| 254 | }),
|
---|
| 255 | generator: cloneObject(module.generator),
|
---|
| 256 | defaultRules: optionalNestedArray(module.defaultRules, r => [...r]),
|
---|
| 257 | rules: nestedArray(module.rules, r => [...r])
|
---|
| 258 | }))
|
---|
| 259 | ),
|
---|
| 260 | name: config.name,
|
---|
| 261 | node: nestedConfig(
|
---|
| 262 | config.node,
|
---|
| 263 | node =>
|
---|
| 264 | node && {
|
---|
| 265 | ...node
|
---|
| 266 | }
|
---|
| 267 | ),
|
---|
| 268 | optimization: nestedConfig(config.optimization, optimization => ({
|
---|
| 269 | ...optimization,
|
---|
| 270 | runtimeChunk: getNormalizedOptimizationRuntimeChunk(
|
---|
| 271 | optimization.runtimeChunk
|
---|
| 272 | ),
|
---|
| 273 | splitChunks: nestedConfig(
|
---|
| 274 | optimization.splitChunks,
|
---|
| 275 | splitChunks =>
|
---|
| 276 | splitChunks && {
|
---|
| 277 | ...splitChunks,
|
---|
| 278 | defaultSizeTypes: splitChunks.defaultSizeTypes
|
---|
| 279 | ? [...splitChunks.defaultSizeTypes]
|
---|
| 280 | : ["..."],
|
---|
| 281 | cacheGroups: cloneObject(splitChunks.cacheGroups)
|
---|
| 282 | }
|
---|
| 283 | ),
|
---|
| 284 | emitOnErrors:
|
---|
| 285 | optimization.noEmitOnErrors !== undefined
|
---|
| 286 | ? handledDeprecatedNoEmitOnErrors(
|
---|
| 287 | optimization.noEmitOnErrors,
|
---|
| 288 | optimization.emitOnErrors
|
---|
| 289 | )
|
---|
| 290 | : optimization.emitOnErrors
|
---|
| 291 | })),
|
---|
| 292 | output: nestedConfig(config.output, output => {
|
---|
| 293 | const { library } = output;
|
---|
| 294 | const libraryAsName = /** @type {LibraryName} */ (library);
|
---|
| 295 | const libraryBase =
|
---|
| 296 | typeof library === "object" &&
|
---|
| 297 | library &&
|
---|
| 298 | !Array.isArray(library) &&
|
---|
| 299 | "type" in library
|
---|
| 300 | ? library
|
---|
| 301 | : libraryAsName || output.libraryTarget
|
---|
| 302 | ? /** @type {LibraryOptions} */ ({
|
---|
| 303 | name: libraryAsName
|
---|
| 304 | })
|
---|
| 305 | : undefined;
|
---|
| 306 | /** @type {OutputNormalized} */
|
---|
| 307 | const result = {
|
---|
| 308 | assetModuleFilename: output.assetModuleFilename,
|
---|
| 309 | asyncChunks: output.asyncChunks,
|
---|
| 310 | charset: output.charset,
|
---|
| 311 | chunkFilename: output.chunkFilename,
|
---|
| 312 | chunkFormat: output.chunkFormat,
|
---|
| 313 | chunkLoading: output.chunkLoading,
|
---|
| 314 | chunkLoadingGlobal: output.chunkLoadingGlobal,
|
---|
| 315 | chunkLoadTimeout: output.chunkLoadTimeout,
|
---|
| 316 | cssFilename: output.cssFilename,
|
---|
| 317 | cssChunkFilename: output.cssChunkFilename,
|
---|
| 318 | clean: output.clean,
|
---|
| 319 | compareBeforeEmit: output.compareBeforeEmit,
|
---|
| 320 | crossOriginLoading: output.crossOriginLoading,
|
---|
| 321 | devtoolFallbackModuleFilenameTemplate:
|
---|
| 322 | output.devtoolFallbackModuleFilenameTemplate,
|
---|
| 323 | devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate,
|
---|
| 324 | devtoolNamespace: output.devtoolNamespace,
|
---|
| 325 | environment: cloneObject(output.environment),
|
---|
| 326 | enabledChunkLoadingTypes: output.enabledChunkLoadingTypes
|
---|
| 327 | ? [...output.enabledChunkLoadingTypes]
|
---|
| 328 | : ["..."],
|
---|
| 329 | enabledLibraryTypes: output.enabledLibraryTypes
|
---|
| 330 | ? [...output.enabledLibraryTypes]
|
---|
| 331 | : ["..."],
|
---|
| 332 | enabledWasmLoadingTypes: output.enabledWasmLoadingTypes
|
---|
| 333 | ? [...output.enabledWasmLoadingTypes]
|
---|
| 334 | : ["..."],
|
---|
| 335 | filename: output.filename,
|
---|
| 336 | globalObject: output.globalObject,
|
---|
| 337 | hashDigest: output.hashDigest,
|
---|
| 338 | hashDigestLength: output.hashDigestLength,
|
---|
| 339 | hashFunction: output.hashFunction,
|
---|
| 340 | hashSalt: output.hashSalt,
|
---|
| 341 | hotUpdateChunkFilename: output.hotUpdateChunkFilename,
|
---|
| 342 | hotUpdateGlobal: output.hotUpdateGlobal,
|
---|
| 343 | hotUpdateMainFilename: output.hotUpdateMainFilename,
|
---|
| 344 | ignoreBrowserWarnings: output.ignoreBrowserWarnings,
|
---|
| 345 | iife: output.iife,
|
---|
| 346 | importFunctionName: output.importFunctionName,
|
---|
| 347 | importMetaName: output.importMetaName,
|
---|
| 348 | scriptType: output.scriptType,
|
---|
| 349 | library: libraryBase && {
|
---|
| 350 | type:
|
---|
| 351 | output.libraryTarget !== undefined
|
---|
| 352 | ? output.libraryTarget
|
---|
| 353 | : libraryBase.type,
|
---|
| 354 | auxiliaryComment:
|
---|
| 355 | output.auxiliaryComment !== undefined
|
---|
| 356 | ? output.auxiliaryComment
|
---|
| 357 | : libraryBase.auxiliaryComment,
|
---|
| 358 | amdContainer:
|
---|
| 359 | output.amdContainer !== undefined
|
---|
| 360 | ? output.amdContainer
|
---|
| 361 | : libraryBase.amdContainer,
|
---|
| 362 | export:
|
---|
| 363 | output.libraryExport !== undefined
|
---|
| 364 | ? output.libraryExport
|
---|
| 365 | : libraryBase.export,
|
---|
| 366 | name: libraryBase.name,
|
---|
| 367 | umdNamedDefine:
|
---|
| 368 | output.umdNamedDefine !== undefined
|
---|
| 369 | ? output.umdNamedDefine
|
---|
| 370 | : libraryBase.umdNamedDefine
|
---|
| 371 | },
|
---|
| 372 | module: output.module,
|
---|
| 373 | path: output.path,
|
---|
| 374 | pathinfo: output.pathinfo,
|
---|
| 375 | publicPath: output.publicPath,
|
---|
| 376 | sourceMapFilename: output.sourceMapFilename,
|
---|
| 377 | sourcePrefix: output.sourcePrefix,
|
---|
| 378 | strictModuleErrorHandling: output.strictModuleErrorHandling,
|
---|
| 379 | strictModuleExceptionHandling: output.strictModuleExceptionHandling,
|
---|
| 380 | trustedTypes: optionalNestedConfig(output.trustedTypes, trustedTypes => {
|
---|
| 381 | if (trustedTypes === true) return {};
|
---|
| 382 | if (typeof trustedTypes === "string")
|
---|
| 383 | return { policyName: trustedTypes };
|
---|
| 384 | return { ...trustedTypes };
|
---|
| 385 | }),
|
---|
| 386 | uniqueName: output.uniqueName,
|
---|
| 387 | wasmLoading: output.wasmLoading,
|
---|
| 388 | webassemblyModuleFilename: output.webassemblyModuleFilename,
|
---|
| 389 | workerPublicPath: output.workerPublicPath,
|
---|
| 390 | workerChunkLoading: output.workerChunkLoading,
|
---|
| 391 | workerWasmLoading: output.workerWasmLoading
|
---|
| 392 | };
|
---|
| 393 | return result;
|
---|
| 394 | }),
|
---|
| 395 | parallelism: config.parallelism,
|
---|
| 396 | performance: optionalNestedConfig(config.performance, performance => {
|
---|
| 397 | if (performance === false) return false;
|
---|
| 398 | return {
|
---|
| 399 | ...performance
|
---|
| 400 | };
|
---|
| 401 | }),
|
---|
| 402 | plugins: /** @type {Plugins} */ (nestedArray(config.plugins, p => [...p])),
|
---|
| 403 | profile: config.profile,
|
---|
| 404 | recordsInputPath:
|
---|
| 405 | config.recordsInputPath !== undefined
|
---|
| 406 | ? config.recordsInputPath
|
---|
| 407 | : config.recordsPath,
|
---|
| 408 | recordsOutputPath:
|
---|
| 409 | config.recordsOutputPath !== undefined
|
---|
| 410 | ? config.recordsOutputPath
|
---|
| 411 | : config.recordsPath,
|
---|
| 412 | resolve: nestedConfig(config.resolve, resolve => ({
|
---|
| 413 | ...resolve,
|
---|
| 414 | byDependency: keyedNestedConfig(resolve.byDependency, cloneObject)
|
---|
| 415 | })),
|
---|
| 416 | resolveLoader: cloneObject(config.resolveLoader),
|
---|
| 417 | snapshot: nestedConfig(config.snapshot, snapshot => ({
|
---|
| 418 | resolveBuildDependencies: optionalNestedConfig(
|
---|
| 419 | snapshot.resolveBuildDependencies,
|
---|
| 420 | resolveBuildDependencies => ({
|
---|
| 421 | timestamp: resolveBuildDependencies.timestamp,
|
---|
| 422 | hash: resolveBuildDependencies.hash
|
---|
| 423 | })
|
---|
| 424 | ),
|
---|
| 425 | buildDependencies: optionalNestedConfig(
|
---|
| 426 | snapshot.buildDependencies,
|
---|
| 427 | buildDependencies => ({
|
---|
| 428 | timestamp: buildDependencies.timestamp,
|
---|
| 429 | hash: buildDependencies.hash
|
---|
| 430 | })
|
---|
| 431 | ),
|
---|
| 432 | resolve: optionalNestedConfig(snapshot.resolve, resolve => ({
|
---|
| 433 | timestamp: resolve.timestamp,
|
---|
| 434 | hash: resolve.hash
|
---|
| 435 | })),
|
---|
| 436 | module: optionalNestedConfig(snapshot.module, module => ({
|
---|
| 437 | timestamp: module.timestamp,
|
---|
| 438 | hash: module.hash
|
---|
| 439 | })),
|
---|
| 440 | immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]),
|
---|
| 441 | managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]),
|
---|
| 442 | unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, p => [...p])
|
---|
| 443 | })),
|
---|
| 444 | stats: nestedConfig(config.stats, stats => {
|
---|
| 445 | if (stats === false) {
|
---|
| 446 | return {
|
---|
| 447 | preset: "none"
|
---|
| 448 | };
|
---|
| 449 | }
|
---|
| 450 | if (stats === true) {
|
---|
| 451 | return {
|
---|
| 452 | preset: "normal"
|
---|
| 453 | };
|
---|
| 454 | }
|
---|
| 455 | if (typeof stats === "string") {
|
---|
| 456 | return {
|
---|
| 457 | preset: stats
|
---|
| 458 | };
|
---|
| 459 | }
|
---|
| 460 | return {
|
---|
| 461 | ...stats
|
---|
| 462 | };
|
---|
| 463 | }),
|
---|
| 464 | target: config.target,
|
---|
| 465 | watch: config.watch,
|
---|
| 466 | watchOptions: cloneObject(config.watchOptions)
|
---|
| 467 | });
|
---|
| 468 |
|
---|
| 469 | /**
|
---|
| 470 | * @param {EntryStatic} entry static entry options
|
---|
| 471 | * @returns {EntryStaticNormalized} normalized static entry options
|
---|
| 472 | */
|
---|
| 473 | const getNormalizedEntryStatic = entry => {
|
---|
| 474 | if (typeof entry === "string") {
|
---|
| 475 | return {
|
---|
| 476 | main: {
|
---|
| 477 | import: [entry]
|
---|
| 478 | }
|
---|
| 479 | };
|
---|
| 480 | }
|
---|
| 481 | if (Array.isArray(entry)) {
|
---|
| 482 | return {
|
---|
| 483 | main: {
|
---|
| 484 | import: entry
|
---|
| 485 | }
|
---|
| 486 | };
|
---|
| 487 | }
|
---|
| 488 | /** @type {EntryStaticNormalized} */
|
---|
| 489 | const result = {};
|
---|
| 490 | for (const key of Object.keys(entry)) {
|
---|
| 491 | const value = entry[key];
|
---|
| 492 | if (typeof value === "string") {
|
---|
| 493 | result[key] = {
|
---|
| 494 | import: [value]
|
---|
| 495 | };
|
---|
| 496 | } else if (Array.isArray(value)) {
|
---|
| 497 | result[key] = {
|
---|
| 498 | import: value
|
---|
| 499 | };
|
---|
| 500 | } else {
|
---|
| 501 | result[key] = {
|
---|
| 502 | import:
|
---|
| 503 | /** @type {EntryDescriptionNormalized["import"]} */
|
---|
| 504 | (
|
---|
| 505 | value.import &&
|
---|
| 506 | (Array.isArray(value.import) ? value.import : [value.import])
|
---|
| 507 | ),
|
---|
| 508 | filename: value.filename,
|
---|
| 509 | layer: value.layer,
|
---|
| 510 | runtime: value.runtime,
|
---|
| 511 | baseUri: value.baseUri,
|
---|
| 512 | publicPath: value.publicPath,
|
---|
| 513 | chunkLoading: value.chunkLoading,
|
---|
| 514 | asyncChunks: value.asyncChunks,
|
---|
| 515 | wasmLoading: value.wasmLoading,
|
---|
| 516 | dependOn:
|
---|
| 517 | /** @type {EntryDescriptionNormalized["dependOn"]} */
|
---|
| 518 | (
|
---|
| 519 | value.dependOn &&
|
---|
| 520 | (Array.isArray(value.dependOn)
|
---|
| 521 | ? value.dependOn
|
---|
| 522 | : [value.dependOn])
|
---|
| 523 | ),
|
---|
| 524 | library: value.library
|
---|
| 525 | };
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
| 528 | return result;
|
---|
| 529 | };
|
---|
| 530 |
|
---|
| 531 | /**
|
---|
| 532 | * @param {OptimizationRuntimeChunk=} runtimeChunk runtimeChunk option
|
---|
| 533 | * @returns {OptimizationRuntimeChunkNormalized=} normalized runtimeChunk option
|
---|
| 534 | */
|
---|
| 535 | const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
|
---|
| 536 | if (runtimeChunk === undefined) return;
|
---|
| 537 | if (runtimeChunk === false) return false;
|
---|
| 538 | if (runtimeChunk === "single") {
|
---|
| 539 | return {
|
---|
| 540 | name: () => "runtime"
|
---|
| 541 | };
|
---|
| 542 | }
|
---|
| 543 | if (runtimeChunk === true || runtimeChunk === "multiple") {
|
---|
| 544 | return {
|
---|
| 545 | /**
|
---|
| 546 | * @param {Entrypoint} entrypoint entrypoint
|
---|
| 547 | * @returns {string} runtime chunk name
|
---|
| 548 | */
|
---|
| 549 | name: entrypoint => `runtime~${entrypoint.name}`
|
---|
| 550 | };
|
---|
| 551 | }
|
---|
| 552 | const { name } = runtimeChunk;
|
---|
| 553 | return {
|
---|
| 554 | name: typeof name === "function" ? name : () => name
|
---|
| 555 | };
|
---|
| 556 | };
|
---|
| 557 |
|
---|
| 558 | module.exports.getNormalizedWebpackOptions = getNormalizedWebpackOptions;
|
---|