webpack 5.106.2 → 5.107.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +2 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/BannerPlugin.js +3 -4
  4. package/lib/Cache.js +3 -6
  5. package/lib/Chunk.js +21 -25
  6. package/lib/ChunkGroup.js +57 -15
  7. package/lib/CompatibilityPlugin.js +8 -7
  8. package/lib/Compilation.js +67 -37
  9. package/lib/Compiler.js +4 -13
  10. package/lib/ContextModule.js +2 -2
  11. package/lib/DefinePlugin.js +2 -2
  12. package/lib/Dependency.js +22 -1
  13. package/lib/DependencyTemplate.js +2 -1
  14. package/lib/EnvironmentPlugin.js +1 -1
  15. package/lib/EvalSourceMapDevToolPlugin.js +8 -10
  16. package/lib/ExportsInfo.js +30 -34
  17. package/lib/ExternalModule.js +91 -26
  18. package/lib/ExternalModuleFactoryPlugin.js +7 -1
  19. package/lib/FileSystemInfo.js +187 -72
  20. package/lib/Generator.js +3 -3
  21. package/lib/HotModuleReplacementPlugin.js +26 -8
  22. package/lib/IgnorePlugin.js +2 -1
  23. package/lib/Module.js +20 -19
  24. package/lib/ModuleFactory.js +1 -1
  25. package/lib/ModuleNotFoundError.js +3 -84
  26. package/lib/ModuleSourceTypeConstants.js +51 -19
  27. package/lib/ModuleTypeConstants.js +12 -3
  28. package/lib/MultiCompiler.js +2 -2
  29. package/lib/NodeStuffPlugin.js +1 -1
  30. package/lib/NormalModule.js +119 -77
  31. package/lib/NormalModuleFactory.js +47 -27
  32. package/lib/Parser.js +1 -1
  33. package/lib/ProgressPlugin.js +129 -56
  34. package/lib/RuntimeGlobals.js +5 -5
  35. package/lib/RuntimeModule.js +9 -7
  36. package/lib/RuntimePlugin.js +12 -1
  37. package/lib/SourceMapDevToolPlugin.js +250 -49
  38. package/lib/Template.js +1 -1
  39. package/lib/TemplatedPathPlugin.js +22 -4
  40. package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
  41. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  42. package/lib/WarnNoModeSetPlugin.js +16 -1
  43. package/lib/Watching.js +2 -3
  44. package/lib/WebpackError.js +3 -77
  45. package/lib/WebpackIsIncludedPlugin.js +1 -1
  46. package/lib/WebpackOptionsApply.js +13 -1
  47. package/lib/asset/AssetBytesGenerator.js +12 -8
  48. package/lib/asset/AssetGenerator.js +36 -22
  49. package/lib/asset/AssetModulesPlugin.js +6 -8
  50. package/lib/asset/AssetSourceGenerator.js +12 -8
  51. package/lib/buildChunkGraph.js +4 -6
  52. package/lib/cache/PackFileCacheStrategy.js +4 -4
  53. package/lib/cli.js +3 -1
  54. package/lib/config/defaults.js +197 -10
  55. package/lib/config/normalization.js +3 -1
  56. package/lib/css/CssGenerator.js +320 -105
  57. package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
  58. package/lib/css/CssLoadingRuntimeModule.js +22 -4
  59. package/lib/{CssModule.js → css/CssModule.js} +15 -15
  60. package/lib/css/CssModulesPlugin.js +168 -88
  61. package/lib/css/CssParser.js +566 -269
  62. package/lib/css/walkCssTokens.js +148 -2
  63. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
  64. package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
  65. package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
  66. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  67. package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
  68. package/lib/dependencies/CommonJsImportsParserPlugin.js +112 -4
  69. package/lib/dependencies/CommonJsRequireDependency.js +67 -4
  70. package/lib/dependencies/ContextDependency.js +1 -1
  71. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  72. package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
  73. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  74. package/lib/dependencies/CssIcssExportDependency.js +332 -67
  75. package/lib/dependencies/CssIcssImportDependency.js +49 -7
  76. package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
  77. package/lib/dependencies/CssImportDependency.js +8 -0
  78. package/lib/dependencies/CssUrlDependency.js +28 -2
  79. package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
  80. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
  81. package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
  82. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
  83. package/lib/dependencies/HarmonyImportDependency.js +10 -2
  84. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
  85. package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
  86. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
  87. package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
  88. package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
  89. package/lib/dependencies/HtmlScriptSrcDependency.js +557 -0
  90. package/lib/dependencies/HtmlSourceDependency.js +128 -0
  91. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  92. package/lib/dependencies/ImportParserPlugin.js +2 -2
  93. package/lib/dependencies/ImportPhase.js +1 -1
  94. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
  95. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
  96. package/lib/dependencies/SystemPlugin.js +1 -1
  97. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  98. package/lib/dependencies/WorkerPlugin.js +2 -2
  99. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
  100. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
  101. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
  102. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
  103. package/lib/{DllModule.js → dll/DllModule.js} +24 -24
  104. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
  105. package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
  106. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
  107. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
  108. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
  109. package/lib/errors/BuildCycleError.js +1 -1
  110. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  111. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  112. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
  113. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
  114. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
  115. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
  116. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
  117. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
  118. package/lib/errors/JSONParseError.js +114 -0
  119. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
  120. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
  121. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
  122. package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
  123. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
  124. package/lib/errors/ModuleNotFoundError.js +91 -0
  125. package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
  126. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
  127. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
  128. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
  129. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
  130. package/lib/errors/NonErrorEmittedError.js +28 -0
  131. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
  132. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
  133. package/lib/errors/WebpackError.js +84 -0
  134. package/lib/html/HtmlGenerator.js +379 -0
  135. package/lib/html/HtmlModulesPlugin.js +429 -0
  136. package/lib/html/HtmlParser.js +1489 -0
  137. package/lib/html/walkHtmlTokens.js +3249 -0
  138. package/lib/ids/IdHelpers.js +2 -1
  139. package/lib/index.js +36 -15
  140. package/lib/javascript/JavascriptModulesPlugin.js +91 -10
  141. package/lib/javascript/JavascriptParser.js +197 -16
  142. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  143. package/lib/json/JsonParser.js +7 -16
  144. package/lib/library/AbstractLibraryPlugin.js +1 -1
  145. package/lib/library/EnableLibraryPlugin.js +1 -1
  146. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
  147. package/lib/library/ModuleLibraryPlugin.js +74 -0
  148. package/lib/node/NodeEnvironmentPlugin.js +4 -2
  149. package/lib/node/nodeConsole.js +113 -64
  150. package/lib/optimize/ConcatenatedModule.js +51 -6
  151. package/lib/optimize/InnerGraph.js +1 -1
  152. package/lib/optimize/InnerGraphPlugin.js +11 -1
  153. package/lib/optimize/MinMaxSizeWarning.js +4 -4
  154. package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
  155. package/lib/optimize/RealContentHashPlugin.js +89 -26
  156. package/lib/optimize/SideEffectsFlagPlugin.js +112 -5
  157. package/lib/optimize/SplitChunksPlugin.js +5 -5
  158. package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
  159. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  160. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  161. package/lib/performance/SizeLimitsPlugin.js +1 -1
  162. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
  163. package/lib/rules/UseEffectRulePlugin.js +4 -3
  164. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -3
  165. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -5
  166. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
  167. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
  168. package/lib/schemes/DataUriPlugin.js +13 -1
  169. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  170. package/lib/serialization/SerializerMiddleware.js +2 -2
  171. package/lib/sharing/ConsumeSharedPlugin.js +4 -10
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  173. package/lib/sharing/ProvideSharedModule.js +1 -1
  174. package/lib/sharing/ProvideSharedPlugin.js +5 -5
  175. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  176. package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
  177. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  178. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  179. package/lib/stats/StatsFactory.js +1 -1
  180. package/lib/typescript/TypeScriptPlugin.js +210 -0
  181. package/lib/url/URLParserPlugin.js +2 -2
  182. package/lib/util/AsyncQueue.js +2 -2
  183. package/lib/util/Hash.js +2 -2
  184. package/lib/util/LocConverter.js +53 -0
  185. package/lib/util/SortableSet.js +1 -1
  186. package/lib/util/cleverMerge.js +2 -2
  187. package/lib/util/comparators.js +3 -3
  188. package/lib/util/concatenate.js +3 -3
  189. package/lib/util/conventions.js +42 -1
  190. package/lib/util/createMappings.js +118 -0
  191. package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
  192. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
  193. package/lib/util/fs.js +8 -8
  194. package/lib/util/hash/md4.js +1 -1
  195. package/lib/util/hash/xxhash64.js +1 -1
  196. package/lib/util/identifier.js +48 -0
  197. package/lib/util/internalSerializables.js +35 -19
  198. package/lib/util/magicComment.js +10 -7
  199. package/lib/util/parseJson.js +2 -73
  200. package/lib/util/source.js +21 -0
  201. package/lib/util/topologicalSort.js +69 -0
  202. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -4
  203. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  204. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
  205. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
  206. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
  207. package/lib/webpack.js +3 -1
  208. package/package.json +24 -22
  209. package/schemas/WebpackOptions.check.js +1 -1
  210. package/schemas/WebpackOptions.json +129 -12
  211. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  212. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  213. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/ProgressPlugin.json +22 -0
  216. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  217. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  218. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  219. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  220. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  221. package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
  222. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  223. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  224. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  225. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  226. package/types.d.ts +1153 -233
  227. package/lib/CaseSensitiveModulesWarning.js +0 -80
  228. package/lib/GraphHelpers.js +0 -49
  229. package/lib/NoModeWarning.js +0 -23
  230. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
  231. /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
  232. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  233. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  234. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  235. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { SyncHook, SyncWaterfallHook } = require("tapable");
8
+ const { SyncBailHook, SyncHook, SyncWaterfallHook } = require("tapable");
9
9
  const {
10
10
  CachedSource,
11
11
  ConcatSource,
@@ -14,8 +14,6 @@ const {
14
14
  ReplaceSource
15
15
  } = require("webpack-sources");
16
16
  const Compilation = require("../Compilation");
17
- const CssModule = require("../CssModule");
18
- const { tryRunOrWebpackError } = require("../HookWebpackError");
19
17
  const HotUpdateChunk = require("../HotUpdateChunk");
20
18
  const { CSS_IMPORT_TYPE, CSS_TYPE } = require("../ModuleSourceTypeConstants");
21
19
  const {
@@ -27,14 +25,16 @@ const {
27
25
  const NormalModule = require("../NormalModule");
28
26
  const RuntimeGlobals = require("../RuntimeGlobals");
29
27
  const Template = require("../Template");
30
- const WebpackError = require("../WebpackError");
31
28
  const CssIcssExportDependency = require("../dependencies/CssIcssExportDependency");
32
29
  const CssIcssImportDependency = require("../dependencies/CssIcssImportDependency");
33
30
  const CssIcssSymbolDependency = require("../dependencies/CssIcssSymbolDependency");
34
31
  const CssImportDependency = require("../dependencies/CssImportDependency");
35
32
  const CssUrlDependency = require("../dependencies/CssUrlDependency");
36
33
  const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
34
+ const { tryRunOrWebpackError } = require("../errors/HookWebpackError");
35
+ const WebpackError = require("../errors/WebpackError");
37
36
  const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
37
+ const ConcatenatedModule = require("../optimize/ConcatenatedModule");
38
38
  const { compareModulesByFullName } = require("../util/comparators");
39
39
  const createHash = require("../util/createHash");
40
40
  const { getUndoPath } = require("../util/identifier");
@@ -42,10 +42,9 @@ const memoize = require("../util/memoize");
42
42
  const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
43
43
  const removeBOM = require("../util/removeBOM");
44
44
  const CssGenerator = require("./CssGenerator");
45
+ const CssModule = require("./CssModule");
45
46
  const CssParser = require("./CssParser");
46
47
 
47
- const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
48
-
49
48
  /** @typedef {import("webpack-sources").Source} Source */
50
49
  /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
51
50
  /** @typedef {import("../Chunk")} Chunk */
@@ -53,13 +52,13 @@ const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
53
52
  /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
54
53
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
55
54
  /** @typedef {import("../Compiler")} Compiler */
56
- /** @typedef {import("../CssModule").Inheritance} Inheritance */
57
- /** @typedef {import("../CssModule").CSSModuleCreateData} CSSModuleCreateData */
55
+ /** @typedef {import("./CssModule").Inheritance} Inheritance */
56
+ /** @typedef {import("./CssModule").CssModuleCreateData} CssModuleCreateData */
58
57
  /** @typedef {import("../Module")} Module */
59
58
  /** @typedef {import("../Module").BuildInfo} BuildInfo */
60
59
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
61
60
  /** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */
62
- /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
61
+ /** @typedef {import("../Chunk").ChunkFilenameTemplate} ChunkFilenameTemplate */
63
62
  /** @typedef {import("../util/Hash")} Hash */
64
63
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
65
64
 
@@ -72,6 +71,7 @@ const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
72
71
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
73
72
  * @property {string} uniqueName the unique name
74
73
  * @property {string} undoPath undo path to css file
74
+ * @property {string=} hash compilation hash
75
75
  * @property {CssModule[]} modules modules
76
76
  */
77
77
 
@@ -83,6 +83,7 @@ const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
83
83
  * @property {CodeGenerationResults=} codeGenerationResults results of code generation
84
84
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
85
85
  * @property {string} undoPath undo path to css file
86
+ * @property {string=} hash compilation hash
86
87
  * @property {WeakMap<Source, ModuleFactoryCacheEntry>} moduleFactoryCache moduleFactoryCache
87
88
  * @property {Source} moduleSourceContent content
88
89
  */
@@ -92,12 +93,14 @@ const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
92
93
  * @typedef {object} CompilationHooks
93
94
  * @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModulePackage
94
95
  * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
96
+ * @property {SyncBailHook<[Chunk, Module[], Compilation], Module[] | undefined | void>} orderModules called for each CSS source type (CSS_IMPORT_TYPE, CSS_TYPE) with the chunk's modules pre-sorted by full module name; return an ordered `Module[]` to override the default import-order topological sort, or return `undefined` to keep the default
95
97
  */
96
98
 
97
99
  /**
98
100
  * Defines the module factory cache entry type used by this module.
99
101
  * @typedef {object} ModuleFactoryCacheEntry
100
102
  * @property {string} undoPath - The undo path to the CSS file
103
+ * @property {string | undefined} hash - The compilation hash
101
104
  * @property {Inheritance} inheritance - The inheritance chain
102
105
  * @property {CachedSource} source - The cached source
103
106
  */
@@ -105,9 +108,6 @@ const publicPathAutoRegex = new RegExp(CssUrlDependency.PUBLIC_PATH_AUTO, "g");
105
108
  const getCssLoadingRuntimeModule = memoize(() =>
106
109
  require("./CssLoadingRuntimeModule")
107
110
  );
108
- const getCssMergeStyleSheetsRuntimeModule = memoize(() =>
109
- require("./CssMergeStyleSheetsRuntimeModule")
110
- );
111
111
  const getCssInjectStyleRuntimeModule = memoize(() =>
112
112
  require("./CssInjectStyleRuntimeModule")
113
113
  );
@@ -161,7 +161,8 @@ class CssModulesPlugin {
161
161
  "module",
162
162
  "renderContext"
163
163
  ]),
164
- chunkHash: new SyncHook(["chunk", "hash", "context"])
164
+ chunkHash: new SyncHook(["chunk", "hash", "context"]),
165
+ orderModules: new SyncBailHook(["chunk", "modules", "compilation"])
165
166
  };
166
167
  compilationHooksMap.set(compilation, hooks);
167
168
  }
@@ -261,11 +262,11 @@ class CssModulesPlugin {
261
262
  case CSS_MODULE_TYPE_MODULE: {
262
263
  defaultMode = "local";
263
264
  compiler.validate(
264
- () => getSchema("CssModuleParserOptions"),
265
+ () => getSchema("CssAutoOrModuleParserOptions"),
265
266
  parserOptions,
266
267
  parserValidationOptions,
267
268
  (options) =>
268
- require("../../schemas/plugins/css/CssModuleParserOptions.check")(
269
+ require("../../schemas/plugins/css/CssAutoOrModuleParserOptions.check")(
269
270
  options
270
271
  )
271
272
  );
@@ -274,11 +275,11 @@ class CssModulesPlugin {
274
275
  case CSS_MODULE_TYPE_AUTO: {
275
276
  defaultMode = "auto";
276
277
  compiler.validate(
277
- () => getSchema("CssModuleParserOptions"),
278
+ () => getSchema("CssAutoOrModuleParserOptions"),
278
279
  parserOptions,
279
280
  parserValidationOptions,
280
281
  (options) =>
281
- require("../../schemas/plugins/css/CssModuleParserOptions.check")(
282
+ require("../../schemas/plugins/css/CssAutoOrModuleParserOptions.check")(
282
283
  options
283
284
  )
284
285
  );
@@ -398,7 +399,7 @@ class CssModulesPlugin {
398
399
  }
399
400
 
400
401
  return new CssModule(
401
- /** @type {CSSModuleCreateData} */
402
+ /** @type {CssModuleCreateData} */
402
403
  ({
403
404
  ...createData,
404
405
  cssLayer: dependency.layer,
@@ -411,7 +412,7 @@ class CssModulesPlugin {
411
412
  }
412
413
 
413
414
  return new CssModule(
414
- /** @type {CSSModuleCreateData} */
415
+ /** @type {CssModuleCreateData} */
415
416
  ({
416
417
  ...createData,
417
418
  cssLayer: dependency.layer,
@@ -424,7 +425,7 @@ class CssModulesPlugin {
424
425
  }
425
426
 
426
427
  return new CssModule(
427
- /** @type {CSSModuleCreateData} */
428
+ /** @type {CssModuleCreateData} */
428
429
  (
429
430
  /** @type {unknown} */ ({
430
431
  ...createData,
@@ -451,44 +452,76 @@ class CssModulesPlugin {
451
452
  JavascriptModulesPlugin.getCompilationHooks(
452
453
  compilation
453
454
  ).renderModuleContent.tap(PLUGIN_NAME, (source, module) => {
454
- if (module instanceof CssModule && module.hot) {
455
- const exportType = module.exportType;
455
+ const injectCssStylesVar =
456
+ module instanceof ConcatenatedModule &&
457
+ module.modules.find(
458
+ (m) =>
459
+ m instanceof CssModule &&
460
+ m.exportType === "style" &&
461
+ !(/** @type {CssGenerator} */ (m.generator)._exportsOnly)
462
+ );
463
+ const injectHMRCode =
464
+ (module instanceof CssModule && module.hot) ||
465
+ (module instanceof ConcatenatedModule &&
466
+ module.rootModule instanceof CssModule &&
467
+ module.rootModule.hot);
468
+
469
+ if (injectCssStylesVar) {
470
+ source = new ConcatSource(
471
+ "var __webpack_css_styles__ = [];",
472
+ "\n",
473
+ source
474
+ );
475
+ }
476
+ if (injectHMRCode) {
477
+ const currentModule = /** @type {CssModule} */ (
478
+ module instanceof ConcatenatedModule ? module.rootModule : module
479
+ );
480
+ const exportType = currentModule.exportType || "link";
456
481
  // When exportType !== "link", modules behave like JavaScript modules
457
- if (exportType && !["link", "style"].includes(exportType)) {
458
- return source;
459
- }
460
- // For exportType === "link", we can optimize with self-acceptance
461
- const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData;
462
- if (!cssData) {
463
- return source;
464
- }
465
- const exports = cssData.exports;
466
- /** @type {Record<string, string>} */
467
- const exportsObj = {};
468
- for (const [key, value] of exports) {
469
- exportsObj[key] = value;
482
+ if (["link", "style"].includes(exportType)) {
483
+ // For exportType === "link", we can optimize with self-acceptance
484
+ const cssData = /** @type {BuildInfo} */ (module.buildInfo)
485
+ .cssData;
486
+ if (!cssData) {
487
+ return source;
488
+ }
489
+ const exports = cssData.exports;
490
+ /** @type {Record<string, string>} */
491
+ const exportsObj = {};
492
+ for (const [key, value] of exports) {
493
+ exportsObj[key] = value;
494
+ }
495
+ const stringifiedExports = JSON.stringify(
496
+ JSON.stringify(exportsObj)
497
+ );
498
+
499
+ const hmrCode = Template.asString([
500
+ "",
501
+ `var __webpack_css_exports__ = ${stringifiedExports};`,
502
+ "// only invalidate when locals change",
503
+ "if (module.hot.data && module.hot.data.__webpack_css_exports__ && module.hot.data.__webpack_css_exports__ != __webpack_css_exports__) {",
504
+ Template.indent("module.hot.invalidate();"),
505
+ "} else {",
506
+ Template.indent("module.hot.accept();"),
507
+ "}",
508
+ "module.hot.dispose(function(data) {",
509
+ Template.indent([
510
+ "data.__webpack_css_exports__ = __webpack_css_exports__;"
511
+ ]),
512
+ "});"
513
+ ]);
514
+
515
+ source = new ConcatSource(source, "\n", new RawSource(hmrCode));
470
516
  }
471
- const stringifiedExports = JSON.stringify(
472
- JSON.stringify(exportsObj)
517
+ }
518
+ if (injectCssStylesVar) {
519
+ /** @type {ConcatSource} */
520
+ (source).add(
521
+ "for (let i = 0; i < __webpack_css_styles__.length; i++) {\n" +
522
+ `${RuntimeGlobals.cssInjectStyle}(__webpack_css_styles__[i][0], __webpack_css_styles__[i][1]);\n` +
523
+ "}"
473
524
  );
474
-
475
- const hmrCode = Template.asString([
476
- "",
477
- `var __webpack_css_exports__ = ${stringifiedExports};`,
478
- "// only invalidate when locals change",
479
- "if (module.hot.data && module.hot.data.__webpack_css_exports__ && module.hot.data.__webpack_css_exports__ != __webpack_css_exports__) {",
480
- Template.indent("module.hot.invalidate();"),
481
- "} else {",
482
- Template.indent("module.hot.accept();"),
483
- "}",
484
- "module.hot.dispose(function(data) {",
485
- Template.indent([
486
- "data.__webpack_css_exports__ = __webpack_css_exports__;"
487
- ]),
488
- "});"
489
- ]);
490
-
491
- return new ConcatSource(source, "\n", new RawSource(hmrCode));
492
525
  }
493
526
 
494
527
  return source;
@@ -577,6 +610,7 @@ class CssModulesPlugin {
577
610
  codeGenerationResults,
578
611
  uniqueName: compilation.outputOptions.uniqueName,
579
612
  undoPath,
613
+ hash,
580
614
  modules,
581
615
  runtimeTemplate
582
616
  },
@@ -663,20 +697,11 @@ class CssModulesPlugin {
663
697
  set.add(RuntimeGlobals.getChunkCssFilename);
664
698
  });
665
699
 
666
- compilation.hooks.runtimeRequirementInTree
667
- .for(RuntimeGlobals.cssMergeStyleSheets)
668
- .tap(PLUGIN_NAME, (chunk) => {
669
- const CssMergeStyleSheetsRuntimeModule =
670
- getCssMergeStyleSheetsRuntimeModule();
671
- compilation.addRuntimeModule(
672
- chunk,
673
- new CssMergeStyleSheetsRuntimeModule()
674
- );
675
- });
676
-
677
700
  compilation.hooks.runtimeRequirementInTree
678
701
  .for(RuntimeGlobals.cssInjectStyle)
679
702
  .tap(PLUGIN_NAME, (chunk, set) => {
703
+ // Same as above: namespace stub is enough.
704
+ set.add(RuntimeGlobals.requireScope);
680
705
  const CssInjectStyleRuntimeModule =
681
706
  getCssInjectStyleRuntimeModule();
682
707
  compilation.addRuntimeModule(
@@ -846,24 +871,33 @@ class CssModulesPlugin {
846
871
  /** @type {string | undefined} */
847
872
  let charset;
848
873
 
874
+ const hooks = CssModulesPlugin.getCompilationHooks(compilation);
875
+
876
+ /**
877
+ * @param {Iterable<Module> | undefined} iter modules pre-sorted by full module name
878
+ * @returns {Module[]} ordered modules
879
+ */
880
+ const orderModules = (iter) => {
881
+ const modules = iter ? [...iter] : [];
882
+ const result = hooks.orderModules.call(chunk, modules, compilation);
883
+ if (result !== undefined) return result;
884
+ return this.getModulesInOrder(chunk, modules, compilation);
885
+ };
886
+
849
887
  return /** @type {CssModule[]} */ ([
850
- ...this.getModulesInOrder(
851
- chunk,
888
+ ...orderModules(
852
889
  chunkGraph.getOrderedChunkModulesIterableBySourceType(
853
890
  chunk,
854
891
  CSS_IMPORT_TYPE,
855
892
  compareModulesByFullName(compilation.compiler)
856
- ),
857
- compilation
893
+ )
858
894
  ),
859
- ...this.getModulesInOrder(
860
- chunk,
895
+ ...orderModules(
861
896
  chunkGraph.getOrderedChunkModulesIterableBySourceType(
862
897
  chunk,
863
898
  CSS_TYPE,
864
899
  compareModulesByFullName(compilation.compiler)
865
- ),
866
- compilation
900
+ )
867
901
  ).map((module) => {
868
902
  if (
869
903
  typeof (/** @type {BuildInfo} */ (module.buildInfo).charset) !==
@@ -906,7 +940,8 @@ class CssModulesPlugin {
906
940
  * @returns {Source | null} css module source
907
941
  */
908
942
  static renderModule(module, renderContext, hooks) {
909
- const { undoPath, moduleFactoryCache, moduleSourceContent } = renderContext;
943
+ const { undoPath, hash, moduleFactoryCache, moduleSourceContent } =
944
+ renderContext;
910
945
  const cacheEntry = moduleFactoryCache.get(moduleSourceContent);
911
946
 
912
947
  /** @type {Inheritance} */
@@ -920,6 +955,7 @@ class CssModulesPlugin {
920
955
  if (
921
956
  cacheEntry &&
922
957
  cacheEntry.undoPath === undoPath &&
958
+ cacheEntry.hash === hash &&
923
959
  cacheEntry.inheritance.length === inheritance.length &&
924
960
  cacheEntry.inheritance.every(([layer, supports, media], i) => {
925
961
  const item = inheritance[i];
@@ -935,19 +971,60 @@ class CssModulesPlugin {
935
971
  const moduleSourceCode =
936
972
  /** @type {string} */
937
973
  (moduleSourceContent.source());
938
- publicPathAutoRegex.lastIndex = 0;
939
- /** @type {Source} */
940
- let moduleSource = new ReplaceSource(moduleSourceContent);
941
- /** @type {null | RegExpExecArray} */
942
- let match;
943
- while ((match = publicPathAutoRegex.exec(moduleSourceCode))) {
944
- /** @type {ReplaceSource} */ (moduleSource).replace(
945
- match.index,
946
- match.index + match[0].length - 1,
947
- undoPath
948
- );
974
+ const replaceSource = new ReplaceSource(moduleSourceContent);
975
+
976
+ const autoPlaceholder = CssUrlDependency.PUBLIC_PATH_AUTO;
977
+ const autoPlaceholderLen = autoPlaceholder.length;
978
+ for (
979
+ let idx = moduleSourceCode.indexOf(autoPlaceholder);
980
+ idx !== -1;
981
+ idx = moduleSourceCode.indexOf(
982
+ autoPlaceholder,
983
+ idx + autoPlaceholderLen
984
+ )
985
+ ) {
986
+ replaceSource.replace(idx, idx + autoPlaceholderLen - 1, undoPath);
949
987
  }
950
988
 
989
+ if (hash) {
990
+ const hashPrefix = CssUrlDependency.PUBLIC_PATH_FULL_HASH;
991
+ const hashPrefixLen = hashPrefix.length;
992
+ const sourceLen = moduleSourceCode.length;
993
+ let idx = moduleSourceCode.indexOf(hashPrefix);
994
+ while (idx !== -1) {
995
+ let digitEnd = idx + hashPrefixLen;
996
+ while (digitEnd < sourceLen) {
997
+ const cc = moduleSourceCode.charCodeAt(digitEnd);
998
+ if (cc < 48 || cc > 57) break;
999
+ digitEnd++;
1000
+ }
1001
+ let nextSearch;
1002
+ if (
1003
+ digitEnd > idx + hashPrefixLen &&
1004
+ digitEnd + 1 < sourceLen &&
1005
+ moduleSourceCode.charCodeAt(digitEnd) === 95 &&
1006
+ moduleSourceCode.charCodeAt(digitEnd + 1) === 95
1007
+ ) {
1008
+ const length = Number.parseInt(
1009
+ moduleSourceCode.slice(idx + hashPrefixLen, digitEnd),
1010
+ 10
1011
+ );
1012
+ replaceSource.replace(
1013
+ idx,
1014
+ digitEnd + 1,
1015
+ length === 0 ? hash : hash.slice(0, length)
1016
+ );
1017
+ nextSearch = digitEnd + 2;
1018
+ } else {
1019
+ nextSearch = idx + hashPrefixLen;
1020
+ }
1021
+ idx = moduleSourceCode.indexOf(hashPrefix, nextSearch);
1022
+ }
1023
+ }
1024
+
1025
+ /** @type {Source} */
1026
+ let moduleSource = replaceSource;
1027
+
951
1028
  for (let i = 0; i < inheritance.length; i++) {
952
1029
  const layer = inheritance[i][0];
953
1030
  const supports = inheritance[i][1];
@@ -987,6 +1064,7 @@ class CssModulesPlugin {
987
1064
  moduleFactoryCache.set(moduleSourceContent, {
988
1065
  inheritance,
989
1066
  undoPath,
1067
+ hash,
990
1068
  source
991
1069
  });
992
1070
  }
@@ -1010,7 +1088,8 @@ class CssModulesPlugin {
1010
1088
  codeGenerationResults,
1011
1089
  modules,
1012
1090
  runtimeTemplate,
1013
- chunkGraph
1091
+ chunkGraph,
1092
+ hash
1014
1093
  },
1015
1094
  hooks
1016
1095
  ) {
@@ -1040,6 +1119,7 @@ class CssModulesPlugin {
1040
1119
  module,
1041
1120
  {
1042
1121
  undoPath,
1122
+ hash,
1043
1123
  chunk,
1044
1124
  chunkGraph,
1045
1125
  codeGenerationResults,
@@ -1072,7 +1152,7 @@ class CssModulesPlugin {
1072
1152
  * Gets chunk filename template.
1073
1153
  * @param {Chunk} chunk chunk
1074
1154
  * @param {OutputOptions} outputOptions output options
1075
- * @returns {TemplatePath} used filename template
1155
+ * @returns {ChunkFilenameTemplate} used filename template
1076
1156
  */
1077
1157
  static getChunkFilenameTemplate(chunk, outputOptions) {
1078
1158
  if (chunk.cssFilenameTemplate) {