| | |
| | | const fs = require("fs"); |
| | | const path = require("path"); |
| | | const { |
| | | CSS_TYPE, |
| | | JAVASCRIPT_TYPE, |
| | | UNKNOWN_TYPE |
| | | } = require("../ModuleSourceTypeConstants"); |
| | | const { |
| | | ASSET_MODULE_TYPE, |
| | | ASSET_MODULE_TYPE_BYTES, |
| | | ASSET_MODULE_TYPE_INLINE, |
| | |
| | | |
| | | /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptionsNormalized */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").Context} Context */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").DevTool} Devtool */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */ |
| | |
| | | /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").HashSalt} HashSalt */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").HashDigest} HashDigest */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").HashDigestLength} HashDigestLength */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").OptimizationNormalized} Optimization */ |
| | |
| | | /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */ |
| | | /** @typedef {import("../Module")} Module */ |
| | | /** @typedef {import("../javascript/EnableChunkLoadingPlugin").ChunkLoadingTypes} ChunkLoadingTypes */ |
| | | /** @typedef {import("../wasm/EnableWasmLoadingPlugin").WasmLoadingTypes} WasmLoadingTypes */ |
| | | /** @typedef {import("./target").PlatformTargetProperties} PlatformTargetProperties */ |
| | | /** @typedef {import("./target").TargetProperties} TargetProperties */ |
| | | |
| | | /** |
| | | * Defines the recursive non nullable type used by this module. |
| | | * @template T |
| | | * @typedef {{ [P in keyof T]-?: T[P] extends object ? RecursiveNonNullable<NonNullable<T[P]>> : NonNullable<T[P]> }} RecursiveNonNullable |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Output & { |
| | | * uniqueName: NonNullable<Output["uniqueName"]>, |
| | | * filename: NonNullable<Output["filename"]>, |
| | |
| | | * hotUpdateChunkFilename: NonNullable<Output["hotUpdateChunkFilename"]>, |
| | | * hotUpdateGlobal: NonNullable<Output["hotUpdateGlobal"]>, |
| | | * assetModuleFilename: NonNullable<Output["assetModuleFilename"]>, |
| | | * webassemblyModuleFilename: NonNullable<Output["webassemblyModuleFilename"]> |
| | | * webassemblyModuleFilename: NonNullable<Output["webassemblyModuleFilename"]>, |
| | | * sourceMapFilename: NonNullable<Output["sourceMapFilename"]>, |
| | | * hotUpdateMainFilename: NonNullable<Output["hotUpdateMainFilename"]>, |
| | | * devtoolNamespace: NonNullable<Output["devtoolNamespace"]>, |
| | | * publicPath: NonNullable<Output["publicPath"]> |
| | | * workerPublicPath: NonNullable<Output["workerPublicPath"]> |
| | | * workerWasmLoading: NonNullable<Output["workerWasmLoading"]> |
| | | * workerChunkLoading: NonNullable<Output["workerChunkLoading"]> |
| | | * publicPath: NonNullable<Output["publicPath"]>, |
| | | * workerPublicPath: NonNullable<Output["workerPublicPath"]>, |
| | | * workerWasmLoading: NonNullable<Output["workerWasmLoading"]>, |
| | | * workerChunkLoading: NonNullable<Output["workerChunkLoading"]>, |
| | | * chunkFormat: NonNullable<Output["chunkFormat"]>, |
| | | * module: NonNullable<Output["module"]>, |
| | | * asyncChunks: NonNullable<Output["asyncChunks"]>, |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {SnapshotOptions & { |
| | | * managedPaths: NonNullable<SnapshotOptions["managedPaths"]>, |
| | | * unmanagedPaths: NonNullable<SnapshotOptions["unmanagedPaths"]>, |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Optimization & { |
| | | * runtimeChunk: NonNullable<Optimization["runtimeChunk"]>, |
| | | * splitChunks: NonNullable<Optimization["splitChunks"]>, |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {ExternalsPresets & { |
| | | * web: NonNullable<ExternalsPresets["web"]>, |
| | | * node: NonNullable<ExternalsPresets["node"]>, |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {InfrastructureLogging & { |
| | | * stream: NonNullable<InfrastructureLogging["stream"]>, |
| | | * level: NonNullable<InfrastructureLogging["level"]>, |
| | |
| | | */ |
| | | |
| | | /** |
| | | * @typedef {WebpackOptionsNormalized |
| | | * & { context: NonNullable<WebpackOptionsNormalized["context"]> } |
| | | * & { infrastructureLogging: InfrastructureLoggingNormalizedWithDefaults } |
| | | * } WebpackOptionsNormalizedWithBaseDefaults |
| | | * Defines the webpack options normalized with base defaults type used by this module. |
| | | * @typedef {WebpackOptionsNormalized & { context: NonNullable<WebpackOptionsNormalized["context"]> } & { infrastructureLogging: InfrastructureLoggingNormalizedWithDefaults }} WebpackOptionsNormalizedWithBaseDefaults |
| | | */ |
| | | |
| | | /** |
| | | * @typedef {WebpackOptionsNormalizedWithBaseDefaults |
| | | * & { target: NonNullable<WebpackOptionsNormalized["target"]> } |
| | | * & { output: OutputNormalizedWithDefaults } |
| | | * & { optimization: OptimizationNormalizedWithDefaults } |
| | | * & { devtool: NonNullable<WebpackOptionsNormalized["devtool"]> } |
| | | * & { stats: NonNullable<WebpackOptionsNormalized["stats"]> } |
| | | * & { node: NonNullable<WebpackOptionsNormalized["node"]> } |
| | | * & { profile: NonNullable<WebpackOptionsNormalized["profile"]> } |
| | | * & { parallelism: NonNullable<WebpackOptionsNormalized["parallelism"]> } |
| | | * & { snapshot: SnapshotNormalizedWithDefaults } |
| | | * & { externalsPresets: ExternalsPresetsNormalizedWithDefaults } |
| | | * & { externalsType: NonNullable<WebpackOptionsNormalized["externalsType"]> } |
| | | * & { watch: NonNullable<WebpackOptionsNormalized["watch"]> } |
| | | * & { performance: NonNullable<WebpackOptionsNormalized["performance"]> } |
| | | * & { recordsInputPath: NonNullable<WebpackOptionsNormalized["recordsInputPath"]> } |
| | | * & { recordsOutputPath: NonNullable<WebpackOptionsNormalized["recordsOutputPath"]> |
| | | * & { dotenv: NonNullable<WebpackOptionsNormalized["dotenv"]> } |
| | | * }} WebpackOptionsNormalizedWithDefaults |
| | | * Defines the webpack options normalized with defaults type used by this module. |
| | | * @typedef {WebpackOptionsNormalizedWithBaseDefaults & { target: NonNullable<WebpackOptionsNormalized["target"]> } & { output: OutputNormalizedWithDefaults } & { optimization: OptimizationNormalizedWithDefaults } & { devtool: NonNullable<WebpackOptionsNormalized["devtool"]> } & { stats: NonNullable<WebpackOptionsNormalized["stats"]> } & { node: NonNullable<WebpackOptionsNormalized["node"]> } & { profile: NonNullable<WebpackOptionsNormalized["profile"]> } & { parallelism: NonNullable<WebpackOptionsNormalized["parallelism"]> } & { snapshot: SnapshotNormalizedWithDefaults } & { externalsPresets: ExternalsPresetsNormalizedWithDefaults } & { externalsType: NonNullable<WebpackOptionsNormalized["externalsType"]> } & { watch: NonNullable<WebpackOptionsNormalized["watch"]> } & { performance: NonNullable<WebpackOptionsNormalized["performance"]> } & { recordsInputPath: NonNullable<WebpackOptionsNormalized["recordsInputPath"]> } & { recordsOutputPath: NonNullable<WebpackOptionsNormalized["recordsOutputPath"]> } & { dotenv: NonNullable<WebpackOptionsNormalized["dotenv"]> }} WebpackOptionsNormalizedWithDefaults |
| | | */ |
| | | |
| | | /** |
| | | * Defines the resolved options type used by this module. |
| | | * @typedef {object} ResolvedOptions |
| | | * @property {PlatformTargetProperties | false} platform - platform target properties |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Sets a constant default value when undefined |
| | | * Processes the provided obj. |
| | | * @template T |
| | | * @template {keyof T} P |
| | | * @param {T} obj an object |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Sets a dynamic default value when undefined, by calling the factory function |
| | | * Processes the provided obj. |
| | | * @template T |
| | | * @template {keyof T} P |
| | | * @param {T} obj an object |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply webpack options base defaults. |
| | | * @param {WebpackOptionsNormalized} options options to be modified |
| | | * @returns {void} |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply webpack options defaults. |
| | | * @param {WebpackOptionsNormalized} options options to be modified |
| | | * @param {number=} compilerIndex index of compiler |
| | | * @returns {ResolvedOptions} Resolved options after apply defaults |
| | |
| | | } |
| | | } |
| | | |
| | | F(options, "devtool", () => (development ? "eval" : false)); |
| | | F( |
| | | options, |
| | | "devtool", |
| | | () => |
| | | /** @type {Devtool} */ ( |
| | | development |
| | | ? [ |
| | | options.experiments.css |
| | | ? { |
| | | type: "css", |
| | | use: "source-map" |
| | | } |
| | | : undefined, |
| | | { |
| | | type: "javascript", |
| | | use: "eval" |
| | | } |
| | | ].filter(Boolean) |
| | | : false |
| | | ) |
| | | ); |
| | | |
| | | D(options, "watch", false); |
| | | D(options, "profile", false); |
| | | D(options, "parallelism", 100); |
| | |
| | | const futureDefaults = |
| | | /** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */ |
| | | (options.experiments.futureDefaults); |
| | | |
| | | F(options, "validate", () => !(futureDefaults === true && production)); |
| | | |
| | | F(options, "cache", () => |
| | | development ? { type: /** @type {"memory"} */ ("memory") } : false |
| | |
| | | |
| | | applyModuleDefaults(options.module, { |
| | | cache, |
| | | hashSalt: /** @type {NonNullable<Output["hashSalt"]>} */ ( |
| | | options.output.hashSalt |
| | | ), |
| | | hashFunction: /** @type {NonNullable<Output["hashFunction"]>} */ ( |
| | | options.output.hashFunction |
| | | ), |
| | | syncWebAssembly: |
| | | /** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */ |
| | | (options.experiments.syncWebAssembly), |
| | |
| | | deferImport: |
| | | /** @type {NonNullable<ExperimentsNormalized["deferImport"]>} */ |
| | | (options.experiments.deferImport), |
| | | sourceImport: |
| | | /** @type {NonNullable<ExperimentsNormalized["sourceImport"]>} */ |
| | | (options.experiments.sourceImport), |
| | | futureDefaults, |
| | | isNode: targetProperties && targetProperties.node === true, |
| | | uniqueName: /** @type {string} */ (options.output.uniqueName), |
| | | targetProperties, |
| | | mode: options.mode |
| | | mode: options.mode, |
| | | outputModule: |
| | | /** @type {NonNullable<WebpackOptionsNormalized["output"]["module"]>} */ |
| | | (options.output.module) |
| | | }); |
| | | |
| | | applyExternalsPresetsDefaults(options.externalsPresets, { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply experiments defaults. |
| | | * @param {ExperimentsNormalized} experiments options |
| | | * @param {object} options options |
| | | * @param {boolean} options.production is production |
| | |
| | | D(experiments, "buildHttp", undefined); |
| | | D(experiments, "cacheUnaffected", experiments.futureDefaults); |
| | | D(experiments, "deferImport", false); |
| | | D(experiments, "sourceImport", false); |
| | | F(experiments, "css", () => (experiments.futureDefaults ? true : undefined)); |
| | | |
| | | if (typeof experiments.buildHttp === "object") { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply cache defaults. |
| | | * @param {CacheOptionsNormalized} cache options |
| | | * @param {object} options options |
| | | * @param {string} options.name name |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply snapshot defaults. |
| | | * @param {SnapshotOptions} snapshot options |
| | | * @param {object} options options |
| | | * @param {boolean} options.production is production |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply javascript parser options defaults. |
| | | * @param {JavascriptParserOptions} parserOptions parser options |
| | | * @param {object} options options |
| | | * @param {boolean} options.futureDefaults is future defaults enabled |
| | | * @param {boolean} options.deferImport is defer import enabled |
| | | * @param {boolean} options.sourceImport is import source enabled |
| | | * @param {boolean} options.isNode is node target platform |
| | | * @param {boolean} options.outputModule is output.module enabled |
| | | * @returns {void} |
| | | */ |
| | | const applyJavascriptParserOptionsDefaults = ( |
| | | parserOptions, |
| | | { futureDefaults, deferImport, isNode } |
| | | { futureDefaults, deferImport, sourceImport, isNode, outputModule } |
| | | ) => { |
| | | D(parserOptions, "unknownContextRequest", "."); |
| | | D(parserOptions, "unknownContextRegExp", false); |
| | |
| | | D(parserOptions, "wrappedContextRecursive", true); |
| | | D(parserOptions, "wrappedContextCritical", false); |
| | | D(parserOptions, "strictThisContextOnImports", false); |
| | | D(parserOptions, "importMeta", true); |
| | | D(parserOptions, "importMeta", outputModule ? "preserve-unknown" : true); |
| | | D(parserOptions, "dynamicImportMode", "lazy"); |
| | | D(parserOptions, "dynamicImportPrefetch", false); |
| | | D(parserOptions, "dynamicImportPreload", false); |
| | |
| | | D(parserOptions, "createRequire", isNode); |
| | | D(parserOptions, "dynamicUrl", true); |
| | | D(parserOptions, "deferImport", deferImport); |
| | | D(parserOptions, "sourceImport", sourceImport); |
| | | if (futureDefaults) D(parserOptions, "exportsPresence", "error"); |
| | | }; |
| | | |
| | | /** |
| | | * Apply json generator options defaults. |
| | | * @param {JsonGeneratorOptions} generatorOptions generator options |
| | | * @returns {void} |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply css generator options defaults. |
| | | * @param {CssGeneratorOptions} generatorOptions generator options |
| | | * @param {object} options options |
| | | * @param {TargetProperties | false} options.targetProperties target properties |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply module defaults. |
| | | * @param {ModuleOptions} module options |
| | | * @param {object} options options |
| | | * @param {boolean} options.cache is caching enabled |
| | |
| | | * @param {string} options.uniqueName the unique name |
| | | * @param {boolean} options.isNode is node target platform |
| | | * @param {boolean} options.deferImport is defer import enabled |
| | | * @param {boolean} options.sourceImport is import source enabled |
| | | * @param {TargetProperties | false} options.targetProperties target properties |
| | | * @param {Mode | undefined} options.mode mode |
| | | * @param {HashSalt} options.hashSalt hash salt |
| | | * @param {HashFunction} options.hashFunction hash function |
| | | * @param {boolean} options.outputModule is output.module enabled |
| | | * @returns {void} |
| | | */ |
| | | const applyModuleDefaults = ( |
| | | module, |
| | | { |
| | | hashSalt, |
| | | hashFunction, |
| | | cache, |
| | | syncWebAssembly, |
| | | asyncWebAssembly, |
| | |
| | | uniqueName, |
| | | targetProperties, |
| | | mode, |
| | | deferImport |
| | | deferImport, |
| | | sourceImport, |
| | | outputModule |
| | | } |
| | | ) => { |
| | | if (cache) { |
| | |
| | | module, |
| | | "unsafeCache", |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {Module} module module |
| | | * @returns {boolean} true, if we want to cache the module |
| | | */ |
| | |
| | | { |
| | | futureDefaults, |
| | | deferImport, |
| | | isNode |
| | | sourceImport, |
| | | isNode, |
| | | outputModule |
| | | } |
| | | ); |
| | | |
| | |
| | | true |
| | | ); |
| | | |
| | | for (const type of [ |
| | | CSS_MODULE_TYPE_AUTO, |
| | | CSS_MODULE_TYPE_MODULE, |
| | | CSS_MODULE_TYPE_GLOBAL |
| | | ]) { |
| | | F(module.parser, type, () => ({})); |
| | | |
| | | D( |
| | | /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.parser[type]), |
| | | "animation", |
| | | true |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.parser[type]), |
| | | "container", |
| | | true |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.parser[type]), |
| | | "customIdents", |
| | | true |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.parser[type]), |
| | | "dashedIdents", |
| | | true |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.parser[type]), |
| | | "function", |
| | | true |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<ParserOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.parser[type]), |
| | | "grid", |
| | | true |
| | | ); |
| | | } |
| | | |
| | | F(module.generator, CSS_MODULE_TYPE, () => ({})); |
| | | |
| | | applyCssGeneratorOptionsDefaults( |
| | |
| | | ); |
| | | |
| | | const localIdentName = |
| | | uniqueName.length > 0 ? "[uniqueName]-[id]-[local]" : "[id]-[local]"; |
| | | mode === "development" |
| | | ? uniqueName.length > 0 |
| | | ? "[uniqueName]-[id]-[local]" |
| | | : "[id]-[local]" |
| | | : "[fullhash]"; |
| | | const localIdentHashSalt = hashSalt; |
| | | const localIdentHashDigest = "base64url"; |
| | | const localIdentHashDigestLength = 6; |
| | | const exportsConvention = "as-is"; |
| | | |
| | | F(module.generator, CSS_MODULE_TYPE_AUTO, () => ({})); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]>} */ |
| | | (module.generator[CSS_MODULE_TYPE_AUTO]), |
| | | "localIdentName", |
| | | localIdentName |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]>} */ |
| | | (module.generator[CSS_MODULE_TYPE_AUTO]), |
| | | "exportsConvention", |
| | | "as-is" |
| | | ); |
| | | for (const type of [ |
| | | CSS_MODULE_TYPE_AUTO, |
| | | CSS_MODULE_TYPE_MODULE, |
| | | CSS_MODULE_TYPE_GLOBAL |
| | | ]) { |
| | | F(module.generator, type, () => ({})); |
| | | |
| | | F(module.generator, CSS_MODULE_TYPE_MODULE, () => ({})); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]>} */ |
| | | (module.generator[CSS_MODULE_TYPE_MODULE]), |
| | | "localIdentName", |
| | | localIdentName |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]>} */ |
| | | (module.generator[CSS_MODULE_TYPE_MODULE]), |
| | | "exportsConvention", |
| | | "as-is" |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.generator[type]), |
| | | "localIdentName", |
| | | localIdentName |
| | | ); |
| | | |
| | | F(module.generator, CSS_MODULE_TYPE_GLOBAL, () => ({})); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.generator[CSS_MODULE_TYPE_GLOBAL]), |
| | | "localIdentName", |
| | | localIdentName |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.generator[CSS_MODULE_TYPE_GLOBAL]), |
| | | "exportsConvention", |
| | | "as-is" |
| | | ); |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.generator[type]), |
| | | "localIdentHashSalt", |
| | | localIdentHashSalt |
| | | ); |
| | | |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]>} */ |
| | | (module.generator[type]), |
| | | "localIdentHashFunction", |
| | | hashFunction |
| | | ); |
| | | |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]>} */ |
| | | (module.generator[type]), |
| | | "localIdentHashDigest", |
| | | localIdentHashDigest |
| | | ); |
| | | |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]>} */ |
| | | (module.generator[type]), |
| | | "localIdentHashDigestLength", |
| | | localIdentHashDigestLength |
| | | ); |
| | | |
| | | D( |
| | | /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_AUTO]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_MODULE]> | NonNullable<GeneratorOptionsByModuleTypeKnown[CSS_MODULE_TYPE_GLOBAL]>} */ |
| | | (module.generator[type]), |
| | | "exportsConvention", |
| | | exportsConvention |
| | | ); |
| | | } |
| | | } |
| | | |
| | | A(module, "defaultRules", () => { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply output defaults. |
| | | * @param {Output} output options |
| | | * @param {object} options options |
| | | * @param {string} options.context context |
| | |
| | | } |
| | | ) => { |
| | | /** |
| | | * Returns a readable library name. |
| | | * @param {Library=} library the library option |
| | | * @returns {string} a readable library name |
| | | */ |
| | |
| | | |
| | | const environment = /** @type {Environment} */ (output.environment); |
| | | /** |
| | | * Returns true, when v is truthy or undefined. |
| | | * @param {boolean | undefined} v value |
| | | * @returns {boolean} true, when v is truthy or undefined |
| | | */ |
| | | const optimistic = (v) => v || v === undefined; |
| | | /** |
| | | * Conditionally optimistic. |
| | | * @param {boolean | undefined} v value |
| | | * @param {boolean | undefined} c condition |
| | | * @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy |
| | |
| | | environment, |
| | | "const", |
| | | () => tp && optimistic(/** @type {boolean | undefined} */ (tp.const)) |
| | | ); |
| | | F( |
| | | environment, |
| | | "methodShorthand", |
| | | () => |
| | | tp && optimistic(/** @type {boolean | undefined} */ (tp.methodShorthand)) |
| | | ); |
| | | F( |
| | | environment, |
| | |
| | | } |
| | | return "[id].css"; |
| | | }); |
| | | D(output, "assetModuleFilename", "[hash][ext][query]"); |
| | | D(output, "assetModuleFilename", "[hash][ext][query][fragment]"); |
| | | D(output, "webassemblyModuleFilename", "[hash].module.wasm"); |
| | | D(output, "compareBeforeEmit", true); |
| | | D(output, "charset", !futureDefaults); |
| | |
| | | throw new Error( |
| | | "For the selected environment is no default ESM chunk format available:\n" + |
| | | "ESM exports can be chosen when 'import()' is available.\n" + |
| | | `JSONP Array push can be chosen when 'document' is available.\n${ |
| | | helpMessage |
| | | }` |
| | | `JSONP Array push can be chosen when 'document' is available.\n${helpMessage}` |
| | | ); |
| | | } else { |
| | | if (tp.document) return "array-push"; |
| | |
| | | : "" |
| | | }\n` + |
| | | "JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" + |
| | | `CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${ |
| | | helpMessage |
| | | }` |
| | | `CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${helpMessage}` |
| | | ); |
| | | } |
| | | } |
| | |
| | | output.module && |
| | | environment.dynamicImport |
| | | ) { |
| | | return "universal"; |
| | | return "import"; |
| | | } |
| | | } |
| | | return false; |
| | |
| | | output.module && |
| | | environment.dynamicImportInWorker |
| | | ) { |
| | | return "universal"; |
| | | return "import"; |
| | | } |
| | | } |
| | | return false; |
| | |
| | | "policyName", |
| | | () => |
| | | /** @type {NonNullable<Output["uniqueName"]>} */ |
| | | (output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack" |
| | | (output.uniqueName).replace(/[^a-z0-9\-#=_/@.%]+/gi, "_") || "webpack" |
| | | ); |
| | | D(trustedTypes, "onPolicyCreationFailure", "stop"); |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided fn. |
| | | * @param {(entryDescription: EntryDescription) => void} fn iterator |
| | | * @returns {void} |
| | | */ |
| | | const forEachEntry = (fn) => { |
| | | for (const name of Object.keys(entry)) { |
| | | fn(/** @type {{[k: string] : EntryDescription}} */ (entry)[name]); |
| | | fn(/** @type {{ [k: string]: EntryDescription }} */ (entry)[name]); |
| | | } |
| | | }; |
| | | A(output, "enabledLibraryTypes", () => { |
| | |
| | | }); |
| | | |
| | | A(output, "enabledChunkLoadingTypes", () => { |
| | | /** @type {ChunkLoadingTypes} */ |
| | | const enabledChunkLoadingTypes = new Set(); |
| | | if (output.chunkLoading) { |
| | | enabledChunkLoadingTypes.add(output.chunkLoading); |
| | |
| | | }); |
| | | |
| | | A(output, "enabledWasmLoadingTypes", () => { |
| | | /** @type {WasmLoadingTypes} */ |
| | | const enabledWasmLoadingTypes = new Set(); |
| | | if (output.wasmLoading) { |
| | | enabledWasmLoadingTypes.add(output.wasmLoading); |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply externals presets defaults. |
| | | * @param {ExternalsPresets} externalsPresets options |
| | | * @param {object} options options |
| | | * @param {TargetProperties | false} options.targetProperties target properties |
| | |
| | | { targetProperties, buildHttp, outputModule } |
| | | ) => { |
| | | /** |
| | | * Checks whether this object is universal. |
| | | * @param {keyof TargetProperties} key a key |
| | | * @returns {boolean} true when target is universal, otherwise false |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply loader defaults. |
| | | * @param {Loader} loader options |
| | | * @param {object} options options |
| | | * @param {TargetProperties | false} options.targetProperties target properties |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply node defaults. |
| | | * @param {WebpackNode} node options |
| | | * @param {object} options options |
| | | * @param {TargetProperties | false} options.targetProperties target properties |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply performance defaults. |
| | | * @param {Performance} performance options |
| | | * @param {object} options options |
| | | * @param {boolean} options.production is production |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply optimization defaults. |
| | | * @param {Optimization} optimization options |
| | | * @param {object} options options |
| | | * @param {boolean} options.production is production |
| | |
| | | const { splitChunks } = optimization; |
| | | if (splitChunks) { |
| | | A(splitChunks, "defaultSizeTypes", () => |
| | | css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"] |
| | | css |
| | | ? [JAVASCRIPT_TYPE, CSS_TYPE, UNKNOWN_TYPE] |
| | | : [JAVASCRIPT_TYPE, UNKNOWN_TYPE] |
| | | ); |
| | | D(splitChunks, "hidePathInfo", production); |
| | | D(splitChunks, "chunks", "async"); |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets resolve defaults. |
| | | * @param {object} options options |
| | | * @param {boolean} options.cache is cache enable |
| | | * @param {string} options.context build context |
| | |
| | | extensions: [...jsExtensions] |
| | | }); |
| | | |
| | | /** @type {() => ResolveOptions} */ |
| | | const workerDeps = () => { |
| | | const options = esmDeps(); |
| | | |
| | | const conditionNames = options.conditionNames |
| | | ? ["worker", ...options.conditionNames] |
| | | : options.conditionNames; |
| | | return { |
| | | ...options, |
| | | conditionNames, |
| | | preferRelative: true |
| | | }; |
| | | }; |
| | | |
| | | /** @type {ResolveOptions} */ |
| | | const resolveOptions = { |
| | | cache, |
| | |
| | | url: { |
| | | preferRelative: true |
| | | }, |
| | | worker: { |
| | | ...esmDeps(), |
| | | preferRelative: true |
| | | }, |
| | | worker: workerDeps(), |
| | | commonjs: cjsDeps(), |
| | | amd: cjsDeps(), |
| | | // for backward-compat: loadModule |
| | |
| | | }; |
| | | |
| | | if (css) { |
| | | /** @type {string[]} */ |
| | | const styleConditions = []; |
| | | |
| | | styleConditions.push("webpack"); |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets resolve loader defaults. |
| | | * @param {object} options options |
| | | * @param {boolean} options.cache is cache enable |
| | | * @returns {ResolveOptions} resolve options |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply infrastructure logging defaults. |
| | | * @param {InfrastructureLogging} infrastructureLogging options |
| | | * @returns {void} |
| | | */ |