| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const { SyncHook, SyncWaterfallHook } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2023-05-10 19:05:00 +08:00
										 |  |  | const { | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	CachedSource, | 
					
						
							| 
									
										
										
										
											2023-05-10 19:05:00 +08:00
										 |  |  | 	ConcatSource, | 
					
						
							|  |  |  | 	PrefixSource, | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	RawSource, | 
					
						
							|  |  |  | 	ReplaceSource | 
					
						
							| 
									
										
										
										
											2023-05-10 19:05:00 +08:00
										 |  |  | } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | const Compilation = require("../Compilation"); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | const CssModule = require("../CssModule"); | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | const { tryRunOrWebpackError } = require("../HookWebpackError"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const HotUpdateChunk = require("../HotUpdateChunk"); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	CSS_MODULE_TYPE, | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	CSS_MODULE_TYPE_AUTO, | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 	CSS_MODULE_TYPE_GLOBAL, | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	CSS_MODULE_TYPE_MODULE | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | } = require("../ModuleTypeConstants"); | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | const NormalModule = require("../NormalModule"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | const SelfModuleFactory = require("../SelfModuleFactory"); | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | const Template = require("../Template"); | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | const WebpackError = require("../WebpackError"); | 
					
						
							| 
									
										
										
										
											2024-11-07 00:11:54 +08:00
										 |  |  | const CssIcssExportDependency = require("../dependencies/CssIcssExportDependency"); | 
					
						
							|  |  |  | const CssIcssImportDependency = require("../dependencies/CssIcssImportDependency"); | 
					
						
							| 
									
										
										
										
											2024-11-08 00:32:00 +08:00
										 |  |  | const CssIcssSymbolDependency = require("../dependencies/CssIcssSymbolDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-01 21:15:19 +08:00
										 |  |  | const CssImportDependency = require("../dependencies/CssImportDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | const CssLocalIdentifierDependency = require("../dependencies/CssLocalIdentifierDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | const CssSelfLocalIdentifierDependency = require("../dependencies/CssSelfLocalIdentifierDependency"); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | const CssUrlDependency = require("../dependencies/CssUrlDependency"); | 
					
						
							|  |  |  | const StaticExportsDependency = require("../dependencies/StaticExportsDependency"); | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2025-02-05 07:21:02 +08:00
										 |  |  | const { compareModulesByIdOrIdentifier } = require("../util/comparators"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const createSchemaValidation = require("../util/create-schema-validation"); | 
					
						
							|  |  |  | const createHash = require("../util/createHash"); | 
					
						
							| 
									
										
										
										
											2023-05-10 19:05:00 +08:00
										 |  |  | const { getUndoPath } = require("../util/identifier"); | 
					
						
							| 
									
										
										
										
											2021-12-03 23:23:09 +08:00
										 |  |  | const memoize = require("../util/memoize"); | 
					
						
							| 
									
										
										
										
											2022-02-01 18:35:12 +08:00
										 |  |  | const nonNumericOnlyHash = require("../util/nonNumericOnlyHash"); | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | const removeBOM = require("../util/removeBOM"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const CssGenerator = require("./CssGenerator"); | 
					
						
							|  |  |  | const CssParser = require("./CssParser"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /** @typedef {import("../Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | /** @typedef {import("../ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */ | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | /** @typedef {import("../CssModule").Inheritance} Inheritance */ | 
					
						
							| 
									
										
										
										
											2025-07-09 18:59:21 +08:00
										 |  |  | /** @typedef {import("../CssModule").CSSModuleCreateData} CSSModuleCreateData */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /** @typedef {import("../Module")} Module */ | 
					
						
							| 
									
										
										
										
											2025-03-07 21:12:22 +08:00
										 |  |  | /** @typedef {import("../Module").BuildInfo} BuildInfo */ | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */ | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | /** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */ | 
					
						
							| 
									
										
										
										
											2024-08-09 01:03:17 +08:00
										 |  |  | /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */ | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | /** @typedef {import("../util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {object} RenderContext | 
					
						
							|  |  |  |  * @property {Chunk} chunk the chunk | 
					
						
							|  |  |  |  * @property {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  |  * @property {CodeGenerationResults} codeGenerationResults results of code generation | 
					
						
							|  |  |  |  * @property {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							|  |  |  |  * @property {string} uniqueName the unique name | 
					
						
							|  |  |  |  * @property {string} undoPath undo path to css file | 
					
						
							|  |  |  |  * @property {CssModule[]} modules modules | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {object} ChunkRenderContext | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  |  * @property {Chunk} chunk the chunk | 
					
						
							|  |  |  |  * @property {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  |  * @property {CodeGenerationResults} codeGenerationResults results of code generation | 
					
						
							|  |  |  |  * @property {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							|  |  |  |  * @property {string} undoPath undo path to css file | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {object} CompilationHooks | 
					
						
							|  |  |  |  * @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModulePackage | 
					
						
							|  |  |  |  * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-03 23:23:09 +08:00
										 |  |  | const getCssLoadingRuntimeModule = memoize(() => | 
					
						
							|  |  |  | 	require("./CssLoadingRuntimeModule") | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string} name name | 
					
						
							| 
									
										
										
										
											2025-03-12 09:56:14 +08:00
										 |  |  |  * @returns {{ oneOf: [{ $ref: string }], definitions: import("../../schemas/WebpackOptions.json")["definitions"] }} schema | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const getSchema = (name) => { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	const { definitions } = require("../../schemas/WebpackOptions.json"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		definitions, | 
					
						
							|  |  |  | 		oneOf: [{ $ref: `#/definitions/${name}` }] | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | const generatorValidationOptions = { | 
					
						
							|  |  |  | 	name: "Css Modules Plugin", | 
					
						
							|  |  |  | 	baseDataPath: "generator" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const validateGeneratorOptions = { | 
					
						
							|  |  |  | 	css: createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssGeneratorOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | 		() => getSchema("CssGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/auto": createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssAutoGeneratorOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | 		() => getSchema("CssAutoGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/module": createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssModuleGeneratorOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | 		() => getSchema("CssModuleGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/global": createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssGlobalGeneratorOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | 		() => getSchema("CssGlobalGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const parserValidationOptions = { | 
					
						
							|  |  |  | 	name: "Css Modules Plugin", | 
					
						
							|  |  |  | 	baseDataPath: "parser" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const validateParserOptions = { | 
					
						
							|  |  |  | 	css: createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssParserOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 		() => getSchema("CssParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/auto": createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssAutoParserOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 		() => getSchema("CssAutoParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/module": createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssModuleParserOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 		() => getSchema("CssModuleParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/global": createSchemaValidation( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		require("../../schemas/plugins/css/CssGlobalParserOptions.check"), | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 		() => getSchema("CssGlobalParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | /** @type {WeakMap<Compilation, CompilationHooks>} */ | 
					
						
							|  |  |  | const compilationHooksMap = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PLUGIN_NAME = "CssModulesPlugin"; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class CssModulesPlugin { | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @returns {CompilationHooks} the attached hooks | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static getCompilationHooks(compilation) { | 
					
						
							|  |  |  | 		if (!(compilation instanceof Compilation)) { | 
					
						
							|  |  |  | 			throw new TypeError( | 
					
						
							|  |  |  | 				"The 'compilation' argument must be an instance of Compilation" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		let hooks = compilationHooksMap.get(compilation); | 
					
						
							|  |  |  | 		if (hooks === undefined) { | 
					
						
							|  |  |  | 			hooks = { | 
					
						
							|  |  |  | 				renderModulePackage: new SyncWaterfallHook([ | 
					
						
							|  |  |  | 					"source", | 
					
						
							|  |  |  | 					"module", | 
					
						
							|  |  |  | 					"renderContext" | 
					
						
							|  |  |  | 				]), | 
					
						
							|  |  |  | 				chunkHash: new SyncHook(["chunk", "hash", "context"]) | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			compilationHooksMap.set(compilation, hooks); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return hooks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 	constructor() { | 
					
						
							|  |  |  | 		/** @type {WeakMap<Source, { undoPath: string, inheritance: Inheritance, source: CachedSource }>} */ | 
					
						
							| 
									
										
										
										
											2024-11-29 19:06:22 +08:00
										 |  |  | 		this._moduleFactoryCache = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 			PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 			(compilation, { normalModuleFactory }) => { | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 				const hooks = CssModulesPlugin.getCompilationHooks(compilation); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | 				const selfFactory = new SelfModuleFactory(compilation.moduleGraph); | 
					
						
							| 
									
										
										
										
											2024-11-08 00:32:00 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssImportDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssImportDependency, | 
					
						
							|  |  |  | 					new CssImportDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssUrlDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssUrlDependency, | 
					
						
							|  |  |  | 					new CssUrlDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssLocalIdentifierDependency, | 
					
						
							|  |  |  | 					new CssLocalIdentifierDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssSelfLocalIdentifierDependency, | 
					
						
							|  |  |  | 					selfFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssSelfLocalIdentifierDependency, | 
					
						
							|  |  |  | 					new CssSelfLocalIdentifierDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2024-11-07 00:11:54 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssIcssImportDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssIcssImportDependency, | 
					
						
							|  |  |  | 					new CssIcssImportDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							| 
									
										
										
										
											2024-11-07 00:11:54 +08:00
										 |  |  | 					CssIcssExportDependency, | 
					
						
							|  |  |  | 					new CssIcssExportDependency.Template() | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-01 20:27:00 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							| 
									
										
										
										
											2024-11-08 00:32:00 +08:00
										 |  |  | 					CssIcssSymbolDependency, | 
					
						
							|  |  |  | 					new CssIcssSymbolDependency.Template() | 
					
						
							| 
									
										
										
										
											2021-12-01 20:27:00 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					StaticExportsDependency, | 
					
						
							|  |  |  | 					new StaticExportsDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				for (const type of [ | 
					
						
							|  |  |  | 					CSS_MODULE_TYPE, | 
					
						
							|  |  |  | 					CSS_MODULE_TYPE_GLOBAL, | 
					
						
							| 
									
										
										
										
											2022-12-16 20:56:14 +08:00
										 |  |  | 					CSS_MODULE_TYPE_MODULE, | 
					
						
							|  |  |  | 					CSS_MODULE_TYPE_AUTO | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				]) { | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 					normalModuleFactory.hooks.createParser | 
					
						
							|  |  |  | 						.for(type) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						.tap(PLUGIN_NAME, (parserOptions) => { | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 							validateParserOptions[type](parserOptions); | 
					
						
							| 
									
										
										
										
											2024-11-01 22:51:22 +08:00
										 |  |  | 							const { url, import: importOption, namedExports } = parserOptions; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							switch (type) { | 
					
						
							| 
									
										
										
										
											2024-10-04 23:19:57 +08:00
										 |  |  | 								case CSS_MODULE_TYPE: | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 									return new CssParser({ | 
					
						
							| 
									
										
										
										
											2024-11-01 22:51:22 +08:00
										 |  |  | 										importOption, | 
					
						
							|  |  |  | 										url, | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 										namedExports | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2024-10-04 23:19:57 +08:00
										 |  |  | 								case CSS_MODULE_TYPE_GLOBAL: | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									return new CssParser({ | 
					
						
							| 
									
										
										
										
											2024-10-04 23:19:57 +08:00
										 |  |  | 										defaultMode: "global", | 
					
						
							| 
									
										
										
										
											2024-11-01 22:51:22 +08:00
										 |  |  | 										importOption, | 
					
						
							|  |  |  | 										url, | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 										namedExports | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 								case CSS_MODULE_TYPE_MODULE: | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									return new CssParser({ | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 										defaultMode: "local", | 
					
						
							| 
									
										
										
										
											2024-11-01 22:51:22 +08:00
										 |  |  | 										importOption, | 
					
						
							|  |  |  | 										url, | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 										namedExports | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2024-10-04 23:19:57 +08:00
										 |  |  | 								case CSS_MODULE_TYPE_AUTO: | 
					
						
							|  |  |  | 									return new CssParser({ | 
					
						
							|  |  |  | 										defaultMode: "auto", | 
					
						
							| 
									
										
										
										
											2024-11-01 22:51:22 +08:00
										 |  |  | 										importOption, | 
					
						
							|  |  |  | 										url, | 
					
						
							| 
									
										
										
										
											2024-10-04 23:19:57 +08:00
										 |  |  | 										namedExports | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 					normalModuleFactory.hooks.createGenerator | 
					
						
							|  |  |  | 						.for(type) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						.tap(PLUGIN_NAME, (generatorOptions) => { | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | 							validateGeneratorOptions[type](generatorOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-06 20:53:42 +08:00
										 |  |  | 							return new CssGenerator( | 
					
						
							|  |  |  | 								generatorOptions, | 
					
						
							|  |  |  | 								compilation.moduleGraph | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 					normalModuleFactory.hooks.createModuleClass | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 						.for(type) | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 						.tap(PLUGIN_NAME, (createData, resolveData) => { | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 							if (resolveData.dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 								// When CSS is imported from CSS there is only one dependency
 | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 								const dependency = resolveData.dependencies[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 								if (dependency instanceof CssImportDependency) { | 
					
						
							|  |  |  | 									const parent = | 
					
						
							|  |  |  | 										/** @type {CssModule} */ | 
					
						
							|  |  |  | 										(compilation.moduleGraph.getParentModule(dependency)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									if (parent instanceof CssModule) { | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 										/** @type {import("../CssModule").Inheritance | undefined} */ | 
					
						
							|  |  |  | 										let inheritance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										if ( | 
					
						
							| 
									
										
										
										
											2024-10-24 05:07:47 +08:00
										 |  |  | 											parent.cssLayer !== undefined || | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 											parent.supports || | 
					
						
							|  |  |  | 											parent.media | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											if (!inheritance) { | 
					
						
							|  |  |  | 												inheritance = []; | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 											inheritance.push([ | 
					
						
							|  |  |  | 												parent.cssLayer, | 
					
						
							|  |  |  | 												parent.supports, | 
					
						
							|  |  |  | 												parent.media | 
					
						
							|  |  |  | 											]); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 										if (parent.inheritance) { | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 											if (!inheritance) { | 
					
						
							|  |  |  | 												inheritance = []; | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 											inheritance.push(...parent.inheritance); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-09 18:59:21 +08:00
										 |  |  | 										return new CssModule( | 
					
						
							|  |  |  | 											/** @type {CSSModuleCreateData} */ | 
					
						
							|  |  |  | 											({ | 
					
						
							|  |  |  | 												...createData, | 
					
						
							|  |  |  | 												cssLayer: dependency.layer, | 
					
						
							|  |  |  | 												supports: dependency.supports, | 
					
						
							|  |  |  | 												media: dependency.media, | 
					
						
							|  |  |  | 												inheritance | 
					
						
							|  |  |  | 											}) | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									return new CssModule( | 
					
						
							|  |  |  | 										/** @type {CSSModuleCreateData} */ | 
					
						
							|  |  |  | 										({ | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 											...createData, | 
					
						
							|  |  |  | 											cssLayer: dependency.layer, | 
					
						
							|  |  |  | 											supports: dependency.supports, | 
					
						
							| 
									
										
										
										
											2025-07-09 18:59:21 +08:00
										 |  |  | 											media: dependency.media | 
					
						
							|  |  |  | 										}) | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-09 18:59:21 +08:00
										 |  |  | 							return new CssModule( | 
					
						
							|  |  |  | 								/** @type {CSSModuleCreateData} */ | 
					
						
							|  |  |  | 								(createData) | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					NormalModule.getCompilationHooks(compilation).processResult.tap( | 
					
						
							|  |  |  | 						PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2025-03-07 21:12:22 +08:00
										 |  |  | 						(result, module) => { | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | 							if (module.type === type) { | 
					
						
							| 
									
										
										
										
											2025-03-07 21:12:22 +08:00
										 |  |  | 								const [source, ...rest] = result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | 								return [removeBOM(source), ...rest]; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2025-03-07 21:12:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							return result; | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				JavascriptModulesPlugin.getCompilationHooks( | 
					
						
							|  |  |  | 					compilation | 
					
						
							|  |  |  | 				).renderModuleContent.tap(PLUGIN_NAME, (source, module) => { | 
					
						
							|  |  |  | 					if (module instanceof CssModule && module.hot) { | 
					
						
							| 
									
										
										
										
											2025-04-20 02:32:59 +08:00
										 |  |  | 						const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData; | 
					
						
							|  |  |  | 						if (!cssData) { | 
					
						
							|  |  |  | 							return source; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						const exports = cssData.exports; | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 						const stringifiedExports = JSON.stringify( | 
					
						
							| 
									
										
										
										
											2024-11-29 18:57:25 +08:00
										 |  |  | 							JSON.stringify( | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 								[...exports].reduce((obj, [key, value]) => { | 
					
						
							| 
									
										
										
										
											2024-11-29 18:57:25 +08:00
										 |  |  | 									obj[key] = value; | 
					
						
							|  |  |  | 									return obj; | 
					
						
							| 
									
										
										
										
											2025-04-23 10:06:20 +08:00
										 |  |  | 								}, /** @type {Record<string, string>} */ ({})) | 
					
						
							| 
									
										
										
										
											2024-11-29 18:57:25 +08:00
										 |  |  | 							) | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 						); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						const hmrCode = Template.asString([ | 
					
						
							|  |  |  | 							"", | 
					
						
							| 
									
										
										
										
											2024-11-30 01:35:09 +08:00
										 |  |  | 							`var __webpack_css_exports__ = ${stringifiedExports};`, | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 							"// only invalidate when locals change", | 
					
						
							| 
									
										
										
										
											2024-11-30 01:35:09 +08:00
										 |  |  | 							"if (module.hot.data && module.hot.data.__webpack_css_exports__ && module.hot.data.__webpack_css_exports__ != __webpack_css_exports__) {", | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 							Template.indent("module.hot.invalidate();"), | 
					
						
							|  |  |  | 							"} else {", | 
					
						
							|  |  |  | 							Template.indent("module.hot.accept();"), | 
					
						
							|  |  |  | 							"}", | 
					
						
							| 
									
										
										
										
											2024-11-30 01:35:09 +08:00
										 |  |  | 							"module.hot.dispose(function(data) { data.__webpack_css_exports__ = __webpack_css_exports__; });" | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 						]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						return new ConcatSource(source, "\n", new RawSource(hmrCode)); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2025-03-07 21:12:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					return source; | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 				const orderedCssModulesPerChunk = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 				compilation.hooks.afterCodeGeneration.tap(PLUGIN_NAME, () => { | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 					const { chunkGraph } = compilation; | 
					
						
							|  |  |  | 					for (const chunk of compilation.chunks) { | 
					
						
							|  |  |  | 						if (CssModulesPlugin.chunkHasCss(chunk, chunkGraph)) { | 
					
						
							|  |  |  | 							orderedCssModulesPerChunk.set( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								this.getOrderedChunkCssModules(chunk, chunkGraph, compilation) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 				compilation.hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, context) => { | 
					
						
							|  |  |  | 					hooks.chunkHash.call(chunk, hash, context); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				compilation.hooks.contentHash.tap(PLUGIN_NAME, (chunk) => { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					const { | 
					
						
							|  |  |  | 						chunkGraph, | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 						moduleGraph, | 
					
						
							|  |  |  | 						runtimeTemplate, | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 						outputOptions: { | 
					
						
							|  |  |  | 							hashSalt, | 
					
						
							|  |  |  | 							hashDigest, | 
					
						
							|  |  |  | 							hashDigestLength, | 
					
						
							|  |  |  | 							hashFunction | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} = compilation; | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 					const hash = createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					if (hashSalt) hash.update(hashSalt); | 
					
						
							| 
									
										
										
										
											2025-09-02 22:12:40 +08:00
										 |  |  | 					const codeGenerationResults = | 
					
						
							|  |  |  | 						/** @type {CodeGenerationResults} */ | 
					
						
							|  |  |  | 						(compilation.codeGenerationResults); | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 					hooks.chunkHash.call(chunk, hash, { | 
					
						
							|  |  |  | 						chunkGraph, | 
					
						
							|  |  |  | 						codeGenerationResults, | 
					
						
							|  |  |  | 						moduleGraph, | 
					
						
							|  |  |  | 						runtimeTemplate | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					const modules = orderedCssModulesPerChunk.get(chunk); | 
					
						
							|  |  |  | 					if (modules) { | 
					
						
							|  |  |  | 						for (const module of modules) { | 
					
						
							|  |  |  | 							hash.update(chunkGraph.getModuleHash(module, chunk.runtime)); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					const digest = /** @type {string} */ (hash.digest(hashDigest)); | 
					
						
							| 
									
										
										
										
											2024-10-24 04:30:31 +08:00
										 |  |  | 					chunk.contentHash.css = nonNumericOnlyHash( | 
					
						
							|  |  |  | 						digest, | 
					
						
							|  |  |  | 						/** @type {number} */ | 
					
						
							|  |  |  | 						(hashDigestLength) | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 				compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					const { chunkGraph } = compilation; | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 					const { hash, chunk, codeGenerationResults, runtimeTemplate } = | 
					
						
							|  |  |  | 						options; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					if (chunk instanceof HotUpdateChunk) return result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 					/** @type {CssModule[] | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 					const modules = orderedCssModulesPerChunk.get(chunk); | 
					
						
							|  |  |  | 					if (modules !== undefined) { | 
					
						
							| 
									
										
										
										
											2024-06-18 21:10:55 +08:00
										 |  |  | 						const { path: filename, info } = compilation.getPathWithInfo( | 
					
						
							|  |  |  | 							CssModulesPlugin.getChunkFilenameTemplate( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								compilation.outputOptions | 
					
						
							|  |  |  | 							), | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								hash, | 
					
						
							|  |  |  | 								runtime: chunk.runtime, | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								contentHashType: "css" | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						const undoPath = getUndoPath( | 
					
						
							|  |  |  | 							filename, | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 							compilation.outputOptions.path, | 
					
						
							| 
									
										
										
										
											2024-06-18 21:10:55 +08:00
										 |  |  | 							false | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 						result.push({ | 
					
						
							|  |  |  | 							render: () => | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 								this.renderChunk( | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										chunk, | 
					
						
							|  |  |  | 										chunkGraph, | 
					
						
							|  |  |  | 										codeGenerationResults, | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 										uniqueName: compilation.outputOptions.uniqueName, | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 										undoPath, | 
					
						
							|  |  |  | 										modules, | 
					
						
							|  |  |  | 										runtimeTemplate | 
					
						
							|  |  |  | 									}, | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 									hooks | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 								), | 
					
						
							| 
									
										
										
										
											2023-05-10 19:05:00 +08:00
										 |  |  | 							filename, | 
					
						
							|  |  |  | 							info, | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 							identifier: `css${chunk.id}`, | 
					
						
							|  |  |  | 							hash: chunk.contentHash.css | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return result; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 				const globalChunkLoading = compilation.outputOptions.chunkLoading; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 				 * @returns {boolean} true, when enabled | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				const isEnabledForChunk = (chunk) => { | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 					const options = chunk.getEntryOptions(); | 
					
						
							|  |  |  | 					const chunkLoading = | 
					
						
							|  |  |  | 						options && options.chunkLoading !== undefined | 
					
						
							|  |  |  | 							? options.chunkLoading | 
					
						
							|  |  |  | 							: globalChunkLoading; | 
					
						
							| 
									
										
										
										
											2024-03-21 22:52:57 +08:00
										 |  |  | 					return chunkLoading === "jsonp" || chunkLoading === "import"; | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 				const onceForChunkSet = new WeakSet(); | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {Chunk} chunk chunk to check | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | 				 * @param {RuntimeRequirements} set runtime requirements | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				const handler = (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 					if (onceForChunkSet.has(chunk)) return; | 
					
						
							|  |  |  | 					onceForChunkSet.add(chunk); | 
					
						
							|  |  |  | 					if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-01 16:50:13 +08:00
										 |  |  | 					set.add(RuntimeGlobals.makeNamespaceObject); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-03 23:23:09 +08:00
										 |  |  | 					const CssLoadingRuntimeModule = getCssLoadingRuntimeModule(); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set)); | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2022-01-13 08:02:15 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hasCssModules) | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 					.tap(PLUGIN_NAME, handler); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.ensureChunkHandlers) | 
					
						
							| 
									
										
										
										
											2024-10-14 00:25:20 +08:00
										 |  |  | 					.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { | 
					
						
							| 
									
										
										
										
											2024-10-03 00:05:39 +08:00
										 |  |  | 						if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2024-10-14 00:25:20 +08:00
										 |  |  | 						if ( | 
					
						
							|  |  |  | 							!chunkGraph.hasModuleInGraph( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								(m) => | 
					
						
							| 
									
										
										
										
											2024-10-14 00:25:20 +08:00
										 |  |  | 									m.type === CSS_MODULE_TYPE || | 
					
						
							|  |  |  | 									m.type === CSS_MODULE_TYPE_GLOBAL || | 
					
						
							|  |  |  | 									m.type === CSS_MODULE_TYPE_MODULE || | 
					
						
							|  |  |  | 									m.type === CSS_MODULE_TYPE_AUTO | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							return; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 00:05:39 +08:00
										 |  |  | 						set.add(RuntimeGlobals.hasOwnProperty); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.getChunkCssFilename); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | 
					
						
							| 
									
										
										
										
											2024-10-14 00:25:20 +08:00
										 |  |  | 					.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { | 
					
						
							| 
									
										
										
										
											2024-10-03 00:05:39 +08:00
										 |  |  | 						if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2024-10-14 00:25:20 +08:00
										 |  |  | 						if ( | 
					
						
							|  |  |  | 							!chunkGraph.hasModuleInGraph( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								(m) => | 
					
						
							| 
									
										
										
										
											2024-10-14 00:25:20 +08:00
										 |  |  | 									m.type === CSS_MODULE_TYPE || | 
					
						
							|  |  |  | 									m.type === CSS_MODULE_TYPE_GLOBAL || | 
					
						
							|  |  |  | 									m.type === CSS_MODULE_TYPE_MODULE || | 
					
						
							|  |  |  | 									m.type === CSS_MODULE_TYPE_AUTO | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							return; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2024-10-03 00:05:39 +08:00
										 |  |  | 						set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.getChunkCssFilename); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {Iterable<Module>} modules unordered modules | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation compilation | 
					
						
							|  |  |  | 	 * @returns {Module[]} ordered modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 	getModulesInOrder(chunk, modules, compilation) { | 
					
						
							|  |  |  | 		if (!modules) return []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 		/** @type {Module[]} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		const modulesList = [...modules]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Get ordered list of modules per chunk group
 | 
					
						
							|  |  |  | 		// Lists are in reverse order to allow to use Array.pop()
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const modulesByChunkGroup = Array.from( | 
					
						
							|  |  |  | 			chunk.groupsIterable, | 
					
						
							|  |  |  | 			(chunkGroup) => { | 
					
						
							|  |  |  | 				const sortedModules = modulesList | 
					
						
							|  |  |  | 					.map((module) => ({ | 
					
						
							|  |  |  | 						module, | 
					
						
							|  |  |  | 						index: chunkGroup.getModulePostOrderIndex(module) | 
					
						
							|  |  |  | 					})) | 
					
						
							|  |  |  | 					.filter((item) => item.index !== undefined) | 
					
						
							|  |  |  | 					.sort( | 
					
						
							|  |  |  | 						(a, b) => | 
					
						
							|  |  |  | 							/** @type {number} */ (b.index) - /** @type {number} */ (a.index) | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 					.map((item) => item.module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return { list: sortedModules, set: new Set(sortedModules) }; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		if (modulesByChunkGroup.length === 1) { | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 			return modulesByChunkGroup[0].list.reverse(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-05 07:21:02 +08:00
										 |  |  | 		const boundCompareModulesByIdOrIdentifier = compareModulesByIdOrIdentifier( | 
					
						
							|  |  |  | 			compilation.chunkGraph | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 11:02:20 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {{ list: Module[] }} a a | 
					
						
							|  |  |  | 		 * @param {{ list: Module[] }} b b | 
					
						
							|  |  |  | 		 * @returns {-1 | 0 | 1} result | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		const compareModuleLists = ({ list: a }, { list: b }) => { | 
					
						
							|  |  |  | 			if (a.length === 0) { | 
					
						
							|  |  |  | 				return b.length === 0 ? 0 : 1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 			if (b.length === 0) return -1; | 
					
						
							| 
									
										
										
										
											2025-02-05 07:21:02 +08:00
										 |  |  | 			return boundCompareModulesByIdOrIdentifier( | 
					
						
							|  |  |  | 				a[a.length - 1], | 
					
						
							|  |  |  | 				b[b.length - 1] | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		modulesByChunkGroup.sort(compareModuleLists); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 		/** @type {Module[]} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		const finalModules = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (;;) { | 
					
						
							|  |  |  | 			const failedModules = new Set(); | 
					
						
							|  |  |  | 			const list = modulesByChunkGroup[0].list; | 
					
						
							|  |  |  | 			if (list.length === 0) { | 
					
						
							|  |  |  | 				// done, everything empty
 | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 			/** @type {Module} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 			let selectedModule = list[list.length - 1]; | 
					
						
							| 
									
										
										
										
											2024-07-31 06:15:03 +08:00
										 |  |  | 			let hasFailed; | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 			outer: for (;;) { | 
					
						
							|  |  |  | 				for (const { list, set } of modulesByChunkGroup) { | 
					
						
							|  |  |  | 					if (list.length === 0) continue; | 
					
						
							|  |  |  | 					const lastModule = list[list.length - 1]; | 
					
						
							|  |  |  | 					if (lastModule === selectedModule) continue; | 
					
						
							|  |  |  | 					if (!set.has(selectedModule)) continue; | 
					
						
							|  |  |  | 					failedModules.add(selectedModule); | 
					
						
							|  |  |  | 					if (failedModules.has(lastModule)) { | 
					
						
							|  |  |  | 						// There is a conflict, try other alternatives
 | 
					
						
							|  |  |  | 						hasFailed = lastModule; | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					selectedModule = lastModule; | 
					
						
							|  |  |  | 					hasFailed = false; | 
					
						
							|  |  |  | 					continue outer; // restart
 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (hasFailed) { | 
					
						
							|  |  |  | 				// There is a not resolve-able conflict with the selectedModule
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:39:18 +08:00
										 |  |  | 				// TODO print better warning
 | 
					
						
							|  |  |  | 				compilation.warnings.push( | 
					
						
							|  |  |  | 					new WebpackError( | 
					
						
							|  |  |  | 						`chunk ${chunk.name || chunk.id}\nConflicting order between ${ | 
					
						
							|  |  |  | 							/** @type {Module} */ | 
					
						
							|  |  |  | 							(hasFailed).readableIdentifier(compilation.requestShortener) | 
					
						
							|  |  |  | 						} and ${selectedModule.readableIdentifier( | 
					
						
							|  |  |  | 							compilation.requestShortener | 
					
						
							|  |  |  | 						)}`
 | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 				selectedModule = /** @type {Module} */ (hasFailed); | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			// Insert the selected module into the final modules list
 | 
					
						
							|  |  |  | 			finalModules.push(selectedModule); | 
					
						
							|  |  |  | 			// Remove the selected module from all lists
 | 
					
						
							|  |  |  | 			for (const { list, set } of modulesByChunkGroup) { | 
					
						
							|  |  |  | 				const lastModule = list[list.length - 1]; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 				if (lastModule === selectedModule) { | 
					
						
							|  |  |  | 					list.pop(); | 
					
						
							|  |  |  | 				} else if (hasFailed && set.has(selectedModule)) { | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 					const idx = list.indexOf(selectedModule); | 
					
						
							|  |  |  | 					if (idx >= 0) list.splice(idx, 1); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			modulesByChunkGroup.sort(compareModuleLists); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return finalModules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation compilation | 
					
						
							|  |  |  | 	 * @returns {Module[]} ordered css modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 	getOrderedChunkCssModules(chunk, chunkGraph, compilation) { | 
					
						
							|  |  |  | 		return [ | 
					
						
							|  |  |  | 			...this.getModulesInOrder( | 
					
						
							|  |  |  | 				chunk, | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** @type {Iterable<Module>} */ | 
					
						
							|  |  |  | 				( | 
					
						
							|  |  |  | 					chunkGraph.getOrderedChunkModulesIterableBySourceType( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						"css-import", | 
					
						
							| 
									
										
										
										
											2025-02-05 07:21:02 +08:00
										 |  |  | 						compareModulesByIdOrIdentifier(chunkGraph) | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 					) | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 				), | 
					
						
							|  |  |  | 				compilation | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			...this.getModulesInOrder( | 
					
						
							|  |  |  | 				chunk, | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** @type {Iterable<Module>} */ | 
					
						
							|  |  |  | 				( | 
					
						
							|  |  |  | 					chunkGraph.getOrderedChunkModulesIterableBySourceType( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						"css", | 
					
						
							| 
									
										
										
										
											2025-02-05 07:21:02 +08:00
										 |  |  | 						compareModulesByIdOrIdentifier(chunkGraph) | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 					) | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 				), | 
					
						
							|  |  |  | 				compilation | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		]; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-03-12 09:56:14 +08:00
										 |  |  | 	 * @param {CssModule} module css module | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 	 * @param {ChunkRenderContext} renderContext options object | 
					
						
							|  |  |  | 	 * @param {CompilationHooks} hooks hooks | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 	 * @returns {Source} css module source | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 	renderModule(module, renderContext, hooks) { | 
					
						
							| 
									
										
										
										
											2024-11-29 19:06:22 +08:00
										 |  |  | 		const { codeGenerationResults, chunk, undoPath } = renderContext; | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 		const codeGenResult = codeGenerationResults.get(module, chunk.runtime); | 
					
						
							|  |  |  | 		const moduleSourceContent = | 
					
						
							|  |  |  | 			/** @type {Source} */ | 
					
						
							|  |  |  | 			( | 
					
						
							|  |  |  | 				codeGenResult.sources.get("css") || | 
					
						
							|  |  |  | 					codeGenResult.sources.get("css-import") | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2024-11-29 19:06:22 +08:00
										 |  |  | 		const cacheEntry = this._moduleFactoryCache.get(moduleSourceContent); | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** @type {Inheritance} */ | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | 		const inheritance = [[module.cssLayer, module.supports, module.media]]; | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 		if (module.inheritance) { | 
					
						
							|  |  |  | 			inheritance.push(...module.inheritance); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		let source; | 
					
						
							|  |  |  | 		if ( | 
					
						
							|  |  |  | 			cacheEntry && | 
					
						
							|  |  |  | 			cacheEntry.undoPath === undoPath && | 
					
						
							|  |  |  | 			cacheEntry.inheritance.every(([layer, supports, media], i) => { | 
					
						
							|  |  |  | 				const item = inheritance[i]; | 
					
						
							|  |  |  | 				if (Array.isArray(item)) { | 
					
						
							|  |  |  | 					return layer === item[0] && supports === item[1] && media === item[2]; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			source = cacheEntry.source; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2024-11-29 19:06:22 +08:00
										 |  |  | 			const moduleSourceCode = | 
					
						
							|  |  |  | 				/** @type {string} */ | 
					
						
							|  |  |  | 				(moduleSourceContent.source()); | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 			const publicPathAutoRegex = new RegExp( | 
					
						
							|  |  |  | 				CssUrlDependency.PUBLIC_PATH_AUTO, | 
					
						
							|  |  |  | 				"g" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			/** @type {Source} */ | 
					
						
							|  |  |  | 			let moduleSource = new ReplaceSource(moduleSourceContent); | 
					
						
							|  |  |  | 			let match; | 
					
						
							|  |  |  | 			while ((match = publicPathAutoRegex.exec(moduleSourceCode))) { | 
					
						
							|  |  |  | 				/** @type {ReplaceSource} */ (moduleSource).replace( | 
					
						
							|  |  |  | 					match.index, | 
					
						
							|  |  |  | 					(match.index += match[0].length - 1), | 
					
						
							|  |  |  | 					undoPath | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (let i = 0; i < inheritance.length; i++) { | 
					
						
							|  |  |  | 				const layer = inheritance[i][0]; | 
					
						
							|  |  |  | 				const supports = inheritance[i][1]; | 
					
						
							|  |  |  | 				const media = inheritance[i][2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (media) { | 
					
						
							|  |  |  | 					moduleSource = new ConcatSource( | 
					
						
							|  |  |  | 						`@media ${media} {\n`, | 
					
						
							|  |  |  | 						new PrefixSource("\t", moduleSource), | 
					
						
							|  |  |  | 						"}\n" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (supports) { | 
					
						
							|  |  |  | 					moduleSource = new ConcatSource( | 
					
						
							|  |  |  | 						`@supports (${supports}) {\n`, | 
					
						
							|  |  |  | 						new PrefixSource("\t", moduleSource), | 
					
						
							|  |  |  | 						"}\n" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// Layer can be anonymous
 | 
					
						
							|  |  |  | 				if (layer !== undefined && layer !== null) { | 
					
						
							|  |  |  | 					moduleSource = new ConcatSource( | 
					
						
							|  |  |  | 						`@layer${layer ? ` ${layer}` : ""} {\n`, | 
					
						
							|  |  |  | 						new PrefixSource("\t", moduleSource), | 
					
						
							|  |  |  | 						"}\n" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (moduleSource) { | 
					
						
							|  |  |  | 				moduleSource = new ConcatSource(moduleSource, "\n"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			source = new CachedSource(moduleSource); | 
					
						
							| 
									
										
										
										
											2024-11-29 19:06:22 +08:00
										 |  |  | 			this._moduleFactoryCache.set(moduleSourceContent, { | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 				inheritance, | 
					
						
							|  |  |  | 				undoPath, | 
					
						
							|  |  |  | 				source | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 		return tryRunOrWebpackError( | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 			() => hooks.renderModulePackage.call(source, module, renderContext), | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 			"CssModulesPlugin.getCompilationHooks().renderModulePackage" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 	 * @param {RenderContext} renderContext the render context | 
					
						
							|  |  |  | 	 * @param {CompilationHooks} hooks hooks | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	 * @returns {Source} generated source | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 	renderChunk( | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			undoPath, | 
					
						
							|  |  |  | 			chunk, | 
					
						
							|  |  |  | 			chunkGraph, | 
					
						
							|  |  |  | 			codeGenerationResults, | 
					
						
							|  |  |  | 			modules, | 
					
						
							|  |  |  | 			runtimeTemplate | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 		hooks | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		const source = new ConcatSource(); | 
					
						
							|  |  |  | 		for (const module of modules) { | 
					
						
							|  |  |  | 			try { | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 				const moduleSource = this.renderModule( | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 					module, | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 					{ | 
					
						
							|  |  |  | 						undoPath, | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						chunkGraph, | 
					
						
							|  |  |  | 						codeGenerationResults, | 
					
						
							|  |  |  | 						runtimeTemplate | 
					
						
							|  |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 					hooks | 
					
						
							| 
									
										
										
										
											2024-10-31 23:18:08 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2024-03-16 19:39:46 +08:00
										 |  |  | 				source.add(moduleSource); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 			} catch (err) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** @type {Error} */ | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 				(err).message += `\nduring rendering of css ${module.identifier()}`; | 
					
						
							|  |  |  | 				throw err; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-08-12 22:12:05 +08:00
										 |  |  | 		chunk.rendered = true; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		return source; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {OutputOptions} outputOptions output options | 
					
						
							| 
									
										
										
										
											2024-08-09 01:03:17 +08:00
										 |  |  | 	 * @returns {TemplatePath} used filename template | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	static getChunkFilenameTemplate(chunk, outputOptions) { | 
					
						
							|  |  |  | 		if (chunk.cssFilenameTemplate) { | 
					
						
							|  |  |  | 			return chunk.cssFilenameTemplate; | 
					
						
							| 
									
										
										
										
											2021-12-17 19:18:01 +08:00
										 |  |  | 		} else if (chunk.canBeInitial()) { | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 			return outputOptions.cssFilename; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 		return outputOptions.cssChunkFilename; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							|  |  |  | 	 * @returns {boolean} true, when the chunk has css | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	static chunkHasCss(chunk, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2021-12-03 02:29:55 +08:00
										 |  |  | 		return ( | 
					
						
							| 
									
										
										
										
											2024-07-31 11:11:11 +08:00
										 |  |  | 			Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")) || | 
					
						
							|  |  |  | 			Boolean( | 
					
						
							|  |  |  | 				chunkGraph.getChunkModulesIterableBySourceType(chunk, "css-import") | 
					
						
							|  |  |  | 			) | 
					
						
							| 
									
										
										
										
											2021-12-03 02:29:55 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = CssModulesPlugin; |