webpack 5.107.2 → 5.108.0

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 (357) hide show
  1. package/hot/dev-server.js +2 -0
  2. package/lib/APIPlugin.js +8 -4
  3. package/lib/CacheFacade.js +7 -0
  4. package/lib/Chunk.js +4 -0
  5. package/lib/ChunkGraph.js +30 -9
  6. package/lib/CircularModulesPlugin.js +190 -0
  7. package/lib/CleanPlugin.js +2 -1
  8. package/lib/Compilation.js +396 -65
  9. package/lib/Compiler.js +25 -11
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextReplacementPlugin.js +4 -0
  14. package/lib/DefinePlugin.js +89 -15
  15. package/lib/Dependency.js +111 -7
  16. package/lib/EntryOptionPlugin.js +39 -2
  17. package/lib/EntryPlugin.js +2 -0
  18. package/lib/ExportsInfo.js +314 -73
  19. package/lib/ExternalModule.js +82 -34
  20. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  21. package/lib/ExternalsPlugin.js +1 -0
  22. package/lib/FileSystemInfo.js +173 -23
  23. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  24. package/lib/FlagDependencyExportsPlugin.js +23 -0
  25. package/lib/FlagDependencyUsagePlugin.js +87 -5
  26. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  27. package/lib/Generator.js +8 -0
  28. package/lib/HotModuleReplacementPlugin.js +65 -28
  29. package/lib/IgnorePlugin.js +1 -0
  30. package/lib/InitFragment.js +5 -0
  31. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  32. package/lib/LazyBarrel.js +361 -0
  33. package/lib/LoaderTargetPlugin.js +1 -0
  34. package/lib/Module.js +21 -42
  35. package/lib/ModuleGraph.js +3 -2
  36. package/lib/ModuleProfile.js +27 -1
  37. package/lib/ModuleTemplate.js +2 -0
  38. package/lib/MultiCompiler.js +2 -0
  39. package/lib/MultiStats.js +1 -0
  40. package/lib/MultiWatching.js +2 -0
  41. package/lib/NodeStuffPlugin.js +22 -17
  42. package/lib/NormalModule.js +142 -80
  43. package/lib/NormalModuleReplacementPlugin.js +2 -0
  44. package/lib/PrefetchPlugin.js +2 -0
  45. package/lib/ProgressPlugin.js +8 -0
  46. package/lib/ProvidePlugin.js +1 -0
  47. package/lib/RawModule.js +20 -16
  48. package/lib/RecordIdsPlugin.js +1 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimePlugin.js +58 -26
  51. package/lib/RuntimeTemplate.js +278 -21
  52. package/lib/SelfModuleFactory.js +1 -0
  53. package/lib/SourceMapDevToolPlugin.js +3 -5
  54. package/lib/Stats.js +1 -0
  55. package/lib/Template.js +8 -2
  56. package/lib/TemplatedPathPlugin.js +473 -131
  57. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  58. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  59. package/lib/WarnNoModeSetPlugin.js +1 -0
  60. package/lib/WatchIgnorePlugin.js +1 -0
  61. package/lib/Watching.js +9 -0
  62. package/lib/WebpackOptionsApply.js +50 -5
  63. package/lib/asset/AssetBytesGenerator.js +11 -3
  64. package/lib/asset/AssetGenerator.js +47 -22
  65. package/lib/asset/AssetModule.js +47 -0
  66. package/lib/asset/AssetModulesPlugin.js +14 -14
  67. package/lib/asset/AssetParser.js +2 -2
  68. package/lib/asset/AssetSourceGenerator.js +8 -0
  69. package/lib/asset/RawDataUrlModule.js +12 -13
  70. package/lib/buildChunkGraph.js +64 -7
  71. package/lib/bun/BunTargetPlugin.js +48 -0
  72. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  73. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  74. package/lib/cache/IdleFileCachePlugin.js +4 -0
  75. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  76. package/lib/cache/PackFileCacheStrategy.js +1 -0
  77. package/lib/cache/ResolverCachePlugin.js +2 -0
  78. package/lib/cache/mergeEtags.js +2 -0
  79. package/lib/cli.js +109 -19
  80. package/lib/config/browserslistTargetHandler.js +99 -0
  81. package/lib/config/defaults.js +147 -7
  82. package/lib/config/defineConfig.js +31 -0
  83. package/lib/config/normalization.js +5 -0
  84. package/lib/config/target.js +181 -2
  85. package/lib/container/ContainerEntryModule.js +15 -14
  86. package/lib/container/ContainerExposedDependency.js +2 -2
  87. package/lib/container/ContainerReferencePlugin.js +1 -1
  88. package/lib/container/FallbackDependency.js +5 -7
  89. package/lib/container/FallbackModule.js +10 -9
  90. package/lib/container/RemoteModule.js +20 -10
  91. package/lib/container/RemoteRuntimeModule.js +14 -12
  92. package/lib/css/CssGenerator.js +353 -327
  93. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  94. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  95. package/lib/css/CssModule.js +52 -23
  96. package/lib/css/CssModulesPlugin.js +107 -124
  97. package/lib/css/CssParser.js +2759 -2205
  98. package/lib/css/syntax.js +2859 -0
  99. package/lib/debug/ProfilingPlugin.js +2 -0
  100. package/lib/deno/DenoTargetPlugin.js +47 -0
  101. package/lib/dependencies/AMDDefineDependency.js +22 -17
  102. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  103. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  104. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  105. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  106. package/lib/dependencies/AMDRequireDependency.js +24 -20
  107. package/lib/dependencies/CachedConstDependency.js +3 -0
  108. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  109. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  110. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  111. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  112. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  113. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  114. package/lib/dependencies/CommonJsPlugin.js +1 -1
  115. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  116. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  117. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  118. package/lib/dependencies/ConstDependency.js +16 -11
  119. package/lib/dependencies/ContextDependency.js +4 -0
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  121. package/lib/dependencies/ContextElementDependency.js +23 -14
  122. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  123. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  124. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  125. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  126. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  127. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  128. package/lib/dependencies/CssImportDependency.js +25 -1
  129. package/lib/dependencies/CssUrlDependency.js +23 -14
  130. package/lib/dependencies/DllEntryDependency.js +9 -13
  131. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  132. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  133. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  134. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  135. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  136. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  137. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  138. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  139. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  140. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  141. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  142. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  143. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  144. package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
  145. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  146. package/lib/dependencies/HarmonyExports.js +4 -1
  147. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  148. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  149. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  150. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  151. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  152. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  153. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  154. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
  155. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  156. package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
  157. package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
  158. package/lib/dependencies/ImportContextDependency.js +5 -9
  159. package/lib/dependencies/ImportDependency.js +44 -2
  160. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  161. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  162. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  163. package/lib/dependencies/ImportParserPlugin.js +19 -0
  164. package/lib/dependencies/ImportWeakDependency.js +1 -0
  165. package/lib/dependencies/JsonExportsDependency.js +9 -9
  166. package/lib/dependencies/LoaderImportDependency.js +1 -0
  167. package/lib/dependencies/LocalModule.js +11 -12
  168. package/lib/dependencies/LocalModuleDependency.js +11 -13
  169. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  170. package/lib/dependencies/ModuleDependency.js +7 -0
  171. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  172. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  173. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  174. package/lib/dependencies/ProvidedDependency.js +31 -27
  175. package/lib/dependencies/PureExpressionDependency.js +7 -9
  176. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  177. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  178. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  179. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  180. package/lib/dependencies/RequireResolveDependency.js +1 -0
  181. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  182. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  183. package/lib/dependencies/StaticExportsDependency.js +10 -10
  184. package/lib/dependencies/SystemPlugin.js +2 -0
  185. package/lib/dependencies/URLContextDependency.js +5 -7
  186. package/lib/dependencies/URLDependency.js +14 -16
  187. package/lib/dependencies/UnsupportedDependency.js +8 -13
  188. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  189. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  190. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  191. package/lib/dependencies/WorkerDependency.js +19 -8
  192. package/lib/dependencies/WorkerPlugin.js +22 -6
  193. package/lib/dependencies/processExportInfo.js +13 -11
  194. package/lib/dll/DelegatedModule.js +29 -15
  195. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  196. package/lib/dll/DelegatedPlugin.js +1 -0
  197. package/lib/dll/DllEntryPlugin.js +3 -0
  198. package/lib/dll/DllModule.js +3 -2
  199. package/lib/dll/DllPlugin.js +16 -0
  200. package/lib/dll/DllReferencePlugin.js +3 -0
  201. package/lib/dll/LibManifestPlugin.js +1 -0
  202. package/lib/electron/ElectronTargetPlugin.js +22 -4
  203. package/lib/errors/ConcurrentCompilationError.js +1 -0
  204. package/lib/errors/HookWebpackError.js +11 -13
  205. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  206. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  207. package/lib/errors/JSONParseError.js +9 -8
  208. package/lib/errors/ModuleBuildError.js +16 -13
  209. package/lib/errors/ModuleDependencyError.js +8 -1
  210. package/lib/errors/ModuleDependencyWarning.js +8 -1
  211. package/lib/errors/ModuleError.js +5 -11
  212. package/lib/errors/ModuleHashingError.js +4 -0
  213. package/lib/errors/ModuleNotFoundError.js +3 -0
  214. package/lib/errors/ModuleParseError.js +5 -11
  215. package/lib/errors/ModuleRestoreError.js +2 -0
  216. package/lib/errors/ModuleStoreError.js +3 -0
  217. package/lib/errors/ModuleWarning.js +7 -11
  218. package/lib/errors/NodeStuffInWebError.js +1 -0
  219. package/lib/errors/NonErrorEmittedError.js +2 -0
  220. package/lib/errors/UnhandledSchemeError.js +1 -0
  221. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  222. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  223. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  224. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  225. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  226. package/lib/hmr/LazyCompilationPlugin.js +30 -6
  227. package/lib/html/HtmlGenerator.js +217 -23
  228. package/lib/html/HtmlModule.js +40 -0
  229. package/lib/html/HtmlModulesPlugin.js +219 -55
  230. package/lib/html/HtmlParser.js +1108 -1099
  231. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  232. package/lib/ids/IdHelpers.js +4 -2
  233. package/lib/index.js +19 -0
  234. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  235. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  236. package/lib/javascript/JavascriptGenerator.js +6 -2
  237. package/lib/javascript/JavascriptModule.js +54 -0
  238. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  239. package/lib/javascript/JavascriptParser.js +285 -158
  240. package/lib/json/JsonModule.js +40 -0
  241. package/lib/json/JsonModulesPlugin.js +7 -0
  242. package/lib/json/JsonParser.js +4 -2
  243. package/lib/library/AssignLibraryPlugin.js +5 -3
  244. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  245. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  246. package/lib/library/ModuleLibraryPlugin.js +24 -5
  247. package/lib/library/SystemLibraryPlugin.js +3 -3
  248. package/lib/node/NodeTargetPlugin.js +1 -0
  249. package/lib/node/NodeWatchFileSystem.js +1 -0
  250. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  251. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  252. package/lib/optimize/ConcatenatedModule.js +395 -77
  253. package/lib/optimize/ConstExportsPlugin.js +211 -0
  254. package/lib/optimize/InlineExports.js +178 -0
  255. package/lib/optimize/InnerGraph.js +372 -275
  256. package/lib/optimize/InnerGraphPlugin.js +196 -99
  257. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  258. package/lib/optimize/RealContentHashPlugin.js +14 -1
  259. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  260. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  261. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  262. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  263. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  264. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  265. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  266. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  267. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  268. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  269. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  270. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  271. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  272. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  273. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  274. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  275. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  276. package/lib/schemes/HttpUriPlugin.js +3 -2
  277. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  278. package/lib/serialization/ArraySerializer.js +4 -8
  279. package/lib/serialization/BinaryMiddleware.js +538 -468
  280. package/lib/serialization/DateObjectSerializer.js +2 -2
  281. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  282. package/lib/serialization/MapObjectSerializer.js +5 -9
  283. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  284. package/lib/serialization/ObjectMiddleware.js +50 -13
  285. package/lib/serialization/PlainObjectSerializer.js +9 -8
  286. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  287. package/lib/serialization/Serializer.js +1 -0
  288. package/lib/serialization/SetObjectSerializer.js +4 -8
  289. package/lib/sharing/ConsumeSharedModule.js +6 -7
  290. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  291. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  292. package/lib/sharing/ProvideSharedDependency.js +30 -15
  293. package/lib/sharing/ProvideSharedModule.js +30 -11
  294. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  295. package/lib/sharing/SharePlugin.js +3 -0
  296. package/lib/sharing/ShareRuntimeModule.js +18 -16
  297. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  298. package/lib/sharing/utils.js +1 -1
  299. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  300. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  301. package/lib/stats/StatsFactory.js +11 -9
  302. package/lib/stats/StatsPrinter.js +9 -2
  303. package/lib/url/URLParserPlugin.js +5 -2
  304. package/lib/util/AsyncQueue.js +10 -0
  305. package/lib/util/LazyBucketSortedSet.js +5 -0
  306. package/lib/util/LazySet.js +6 -4
  307. package/lib/util/LocConverter.js +11 -1
  308. package/lib/util/Semaphore.js +1 -0
  309. package/lib/util/SourceProcessor.js +106 -0
  310. package/lib/util/TupleSet.js +1 -0
  311. package/lib/util/WeakTupleMap.js +27 -1
  312. package/lib/util/chainedImports.js +3 -3
  313. package/lib/util/comparators.js +2 -2
  314. package/lib/util/concatenate.js +31 -7
  315. package/lib/util/createHash.js +0 -1
  316. package/lib/util/deterministicGrouping.js +19 -12
  317. package/lib/util/extractSourceMap.js +1 -1
  318. package/lib/util/findGraphRoots.js +2 -0
  319. package/lib/util/fs.js +10 -5
  320. package/lib/util/hash/DebugHash.js +1 -0
  321. package/lib/util/hash/hash-digest.js +24 -15
  322. package/lib/util/identifier.js +7 -0
  323. package/lib/util/internalSerializables.js +11 -2
  324. package/lib/util/magicComment.js +42 -0
  325. package/lib/util/makeSerializable.js +1 -0
  326. package/lib/util/nonNumericOnlyHash.js +30 -1
  327. package/lib/util/property.js +7 -1
  328. package/lib/util/publicPathPlaceholder.js +64 -0
  329. package/lib/util/registerExternalSerializer.js +4 -4
  330. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  331. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  333. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  334. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  335. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  336. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  337. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  338. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  339. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  340. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  341. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  342. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  343. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  344. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  345. package/package.json +35 -27
  346. package/schemas/WebpackOptions.check.js +1 -1
  347. package/schemas/WebpackOptions.json +212 -3
  348. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  349. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  350. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  351. package/schemas/plugins/HtmlParserOptions.json +3 -0
  352. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  353. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  354. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  355. package/types.d.ts +1456 -290
  356. package/lib/css/walkCssTokens.js +0 -2020
  357. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -23,15 +23,24 @@ const {
23
23
  JAVASCRIPT_AND_CSS_TEXT_TYPES,
24
24
  JAVASCRIPT_AND_CSS_TYPES,
25
25
  JAVASCRIPT_TYPE,
26
- JAVASCRIPT_TYPES
26
+ JAVASCRIPT_TYPES,
27
+ NO_TYPES
27
28
  } = require("../ModuleSourceTypeConstants");
28
29
  const RuntimeGlobals = require("../RuntimeGlobals");
29
30
  const Template = require("../Template");
31
+ const { getPresentKinds } = require("../TemplatedPathPlugin");
30
32
  const CssImportDependency = require("../dependencies/CssImportDependency");
31
33
  const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
32
34
 
33
35
  const { encodeMappings } = require("../util/createMappings");
34
36
  const memoize = require("../util/memoize");
37
+ const {
38
+ PUBLIC_PATH_FULL_HASH,
39
+ walkFullHashPlaceholders
40
+ } = require("../util/publicPathPlaceholder");
41
+
42
+ // Avoids `type.split("/")[0]` allocation on the `getTypes` hot path.
43
+ const CSS_TYPE_PREFIX = `${CSS_TYPE}/`;
35
44
 
36
45
  /** @typedef {import("webpack-sources").Source} Source */
37
46
  /** @typedef {import("../../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
@@ -52,6 +61,8 @@ const memoize = require("../util/memoize");
52
61
  /** @typedef {import("../util/Hash")} Hash */
53
62
  /** @typedef {import("./CssModulesPlugin").ModuleFactoryCacheEntry} ModuleFactoryCacheEntry */
54
63
  /** @typedef {import("./CssModule")} CssModule */
64
+ /** @typedef {import("./CssModule").CssModuleBuildInfo} CssModuleBuildInfo */
65
+ /** @typedef {import("./CssModule").CssModuleBuildMeta} CssModuleBuildMeta */
55
66
  /** @typedef {import("../Compilation")} Compilation */
56
67
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
57
68
  /** @typedef {import("../../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
@@ -65,10 +76,7 @@ const getCssModulesPlugin = memoize(() => require("./CssModulesPlugin"));
65
76
  /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
66
77
 
67
78
  /**
68
- * Build a v3 source map that maps each line in `generatedJs` containing a
69
- * known CSS-class export entry back to the corresponding selector position
70
- * in the original CSS. Lines without an associated export are left
71
- * unmapped — devtools simply shows them as part of the bundled JS.
79
+ * Build a v3 source map mapping CSS-class export lines back to their selector positions.
72
80
  * @param {string} generatedJs the generated JS string
73
81
  * @param {ExportLocsMap} exportLocs map of export names to CSS source location
74
82
  * @param {string} cssContent original CSS source content
@@ -83,14 +91,29 @@ const buildExportsSourceMap = (
83
91
  ) => {
84
92
  const lines = generatedJs.split("\n");
85
93
 
86
- const lineByExport = new Map();
94
+ // O(L) pass: match `\t"<name>": <value>` lines against export names.
95
+ const keyToName = new Map();
87
96
  for (const [exportName] of exportLocs) {
88
- const needle = `${JSON.stringify(exportName)}:`;
89
- for (let i = 0; i < lines.length; i++) {
90
- if (lines[i].includes(needle)) {
91
- lineByExport.set(exportName, i);
92
- break;
97
+ keyToName.set(JSON.stringify(exportName), exportName);
98
+ }
99
+ const lineByExport = new Map();
100
+ for (let i = 0; i < lines.length && lineByExport.size < keyToName.size; i++) {
101
+ const line = lines[i];
102
+ if (line.charCodeAt(0) !== 9 || line.charCodeAt(1) !== 34) continue;
103
+ let j = 2;
104
+ while (j < line.length) {
105
+ const c = line.charCodeAt(j);
106
+ if (c === 92) {
107
+ j += 2;
108
+ continue;
93
109
  }
110
+ if (c === 34) break;
111
+ j++;
112
+ }
113
+ if (line.charCodeAt(j + 1) !== 58) continue;
114
+ const name = keyToName.get(line.slice(1, j + 1));
115
+ if (name !== undefined && !lineByExport.has(name)) {
116
+ lineByExport.set(name, i);
94
117
  }
95
118
  }
96
119
 
@@ -98,9 +121,7 @@ const buildExportsSourceMap = (
98
121
  const perLine = lines.map(() => null);
99
122
  for (const [exportName, genLine] of lineByExport) {
100
123
  const pos = /** @type {SourcePosition} */ (exportLocs.get(exportName));
101
- // Source-map V3 uses 0-based lines and 0-based columns. webpack's
102
- // dependency `loc` uses 1-based lines and 0-based columns, so subtract
103
- // one from the line.
124
+ // V3 source maps are 0-based; webpack `loc` lines are 1-based.
104
125
  perLine[genLine] = {
105
126
  generatedColumn: 0,
106
127
  sourceIndex: 0,
@@ -127,12 +148,31 @@ class CssGenerator extends Generator {
127
148
  */
128
149
  constructor(options, moduleGraph) {
129
150
  super();
151
+ /** @type {CssModuleGeneratorOptions} */
130
152
  this.options = options;
153
+ /** @type {boolean | undefined} */
131
154
  this._exportsOnly = options.exportsOnly;
155
+ /** @type {boolean | undefined} */
132
156
  this._esModule = options.esModule;
157
+ /** @type {ModuleGraph} */
133
158
  this._moduleGraph = moduleGraph;
134
159
  /** @type {WeakMap<Source, ModuleFactoryCacheEntry>} */
135
160
  this._moduleFactoryCache = new WeakMap();
161
+ const localIdentName = options.localIdentName;
162
+ // Detect hash placeholders via the canonical template parser so this stays
163
+ // in sync with `interpolate`'s grammar.
164
+ const isFn = typeof localIdentName === "function";
165
+ const kinds =
166
+ typeof localIdentName === "string"
167
+ ? getPresentKinds(localIdentName)
168
+ : undefined;
169
+ /** @type {boolean} */
170
+ this._localIdentNeedsHash =
171
+ isFn ||
172
+ (kinds !== undefined && (kinds.has("fullhash") || kinds.has("hash")));
173
+ /** @type {boolean} */
174
+ this._localIdentNeedsContentHash =
175
+ isFn || (kinds !== undefined && kinds.has("contenthash"));
136
176
  }
137
177
 
138
178
  /**
@@ -149,201 +189,6 @@ class CssGenerator extends Generator {
149
189
  return undefined;
150
190
  }
151
191
 
152
- /**
153
- * Returns the `@charset` that will appear at the start of this module's
154
- * default export, walking through text imports when the module has no
155
- * local `@charset` of its own.
156
- * @param {NormalModule} module the module
157
- * @param {ModuleGraph} moduleGraph module graph
158
- * @param {WeakSet<NormalModule>=} visited cycle guard
159
- * @returns {string | undefined} the effective charset
160
- */
161
- _getEffectiveCharset(module, moduleGraph, visited = new WeakSet()) {
162
- if (!module || visited.has(module)) return undefined;
163
- const exportType = /** @type {CssModule} */ (module).exportType;
164
- if (exportType !== "text" && exportType !== "css-style-sheet") {
165
- return undefined;
166
- }
167
- visited.add(module);
168
- const own =
169
- module.buildInfo && /** @type {BuildInfo} */ (module.buildInfo).charset;
170
- if (own !== undefined) return own;
171
- if (exportType !== "text") return undefined;
172
- for (const dep of module.dependencies) {
173
- if (dep instanceof CssImportDependency) {
174
- const depModule = /** @type {NormalModule} */ (
175
- moduleGraph.getModule(dep)
176
- );
177
- const inherited = this._getEffectiveCharset(
178
- depModule,
179
- moduleGraph,
180
- visited
181
- );
182
- if (inherited !== undefined) return inherited;
183
- }
184
- }
185
- return undefined;
186
- }
187
-
188
- /**
189
- * Generate JavaScript expressions that evaluate each `@import`'d module
190
- * for side effects. Only used by `style` exportType, where each imported
191
- * style module injects its own `<style>` element independently — no
192
- * content merging happens at the parent. `text` and `css-style-sheet`
193
- * instead inline their imports at build time via
194
- * {@link CssGenerator#_generateMergedContentSource}.
195
- * @param {NormalModule} module the module to generate CSS text for
196
- * @param {GenerateContext} generateContext the generate context
197
- * @returns {string[]} JS expressions, one per `@import` dependency
198
- */
199
- _generateImportSideEffects(module, generateContext) {
200
- const { moduleGraph, concatenationScope } = generateContext;
201
- const parts = [];
202
-
203
- for (const dep of module.dependencies) {
204
- if (!(dep instanceof CssImportDependency)) continue;
205
- const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
206
- // Concat-scoped deps are inlined into the same module; their side
207
- // effect (own `<style>` injection) is emitted at the dep's own
208
- // site, so no explicit reference is needed here.
209
- if (concatenationScope && concatenationScope.isModuleInScope(depModule)) {
210
- continue;
211
- }
212
- parts.push(
213
- generateContext.runtimeTemplate.moduleExports({
214
- module: depModule,
215
- chunkGraph: generateContext.chunkGraph,
216
- request: depModule.userRequest,
217
- weak: false,
218
- runtimeRequirements: generateContext.runtimeRequirements
219
- })
220
- );
221
- }
222
-
223
- return parts;
224
- }
225
-
226
- /**
227
- * Build a single CSS `Source` that contains, in source order, the rendered
228
- * CSS text of every transitively `@import`'d module followed by the
229
- * current module's own CSS text. Imports are inlined at build time so
230
- * the resulting `Source` carries a single, accurate source map covering
231
- * every contributing file — no runtime merge helper required.
232
- *
233
- * Only `text` / `css-style-sheet` imports contribute CSS text; `link` and
234
- * `style` imports are emitted separately (own `.css` file or own
235
- * `<style>` injection) and are skipped here.
236
- *
237
- * `ancestors` tracks the path from the top-level caller down to the
238
- * current module — not every module ever visited. A module reappearing
239
- * along a sibling branch (a "diamond import" like two different files
240
- * each `@import`'ing the same shared module) must be inlined every time,
241
- * matching the prior runtime behavior where each `default` getter was
242
- * invoked at every import site.
243
- * @param {NormalModule} module the module to render
244
- * @param {GenerateContext} generateContext the generate context
245
- * @param {Set<NormalModule>} ancestors modules on the current path
246
- * @returns {Source | null} merged CSS source, or null when the module has no content
247
- */
248
- _generateMergedContentSource(module, generateContext, ancestors) {
249
- if (ancestors.has(module)) return null;
250
- ancestors.add(module);
251
- try {
252
- const { moduleGraph } = generateContext;
253
- /** @type {Source[]} */
254
- const parts = [];
255
-
256
- for (const dep of module.dependencies) {
257
- if (!(dep instanceof CssImportDependency)) continue;
258
- const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
259
- if (!depModule) continue;
260
- const depExportType = depModule.exportType;
261
- if (depExportType !== "text" && depExportType !== "css-style-sheet") {
262
- continue;
263
- }
264
- const depMerged = this._generateMergedContentSource(
265
- depModule,
266
- generateContext,
267
- ancestors
268
- );
269
- if (depMerged) parts.push(depMerged);
270
- }
271
-
272
- const own = this._generateContentSource(module, generateContext);
273
- if (own) parts.push(own);
274
-
275
- if (parts.length === 0) return null;
276
- if (parts.length === 1) return parts[0];
277
- return new ConcatSource(...parts);
278
- } finally {
279
- ancestors.delete(module);
280
- }
281
- }
282
-
283
- /**
284
- * Generate CSS source for the current module
285
- * @param {NormalModule} module the module to generate CSS source for
286
- * @param {GenerateContext} generateContext the generate context
287
- * @returns {Source | null} the CSS source
288
- */
289
- _generateContentSource(module, generateContext) {
290
- const moduleSourceContent = /** @type {Source} */ (
291
- this.generate(module, {
292
- ...generateContext,
293
- type: CSS_TYPE
294
- })
295
- );
296
-
297
- if (!moduleSourceContent) {
298
- return null;
299
- }
300
-
301
- const compilation = generateContext.runtimeTemplate.compilation;
302
- // For non-link exportTypes (style, text, css-style-sheet), url() in the CSS
303
- // is resolved relative to the document URL (for <style> tags and CSSStyleSheet),
304
- // not relative to any output file. Use empty undoPath so urls are relative to
305
- // the output root.
306
- const undoPath = "";
307
-
308
- const CssModulesPlugin = getCssModulesPlugin();
309
- const hooks = CssModulesPlugin.getCompilationHooks(compilation);
310
- return CssModulesPlugin.renderModule(
311
- /** @type {CssModule} */ (module),
312
- {
313
- undoPath,
314
- moduleSourceContent,
315
- moduleFactoryCache: this._moduleFactoryCache,
316
- runtimeTemplate: generateContext.runtimeTemplate
317
- },
318
- hooks
319
- );
320
- }
321
-
322
- /**
323
- * Serialize a CSS Source into a JS string literal with an optional
324
- * inline `sourceMappingURL` data URI so DevTools can resolve the
325
- * original sources at runtime.
326
- * @param {Source} cssSource the CSS source
327
- * @param {import("../../declarations/WebpackOptions").DevTool | undefined} devtool the devtool option
328
- * @returns {Source} a Source representing a JS string literal
329
- */
330
- _cssToJsLiteral(cssSource, devtool) {
331
- const { source, map } = cssSource.sourceAndMap();
332
- let content = /** @type {string} */ (source);
333
- if (map) {
334
- const inlineMap =
335
- typeof devtool === "string" && devtool.includes("nosources")
336
- ? { ...map, sourcesContent: undefined }
337
- : map;
338
- const base64Map = Buffer.from(JSON.stringify(inlineMap), "utf8").toString(
339
- "base64"
340
- );
341
- const trailingNewline = content.endsWith("\n") ? "" : "\n";
342
- content += `${trailingNewline}/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}*/`;
343
- }
344
- return new RawSource(JSON.stringify(content));
345
- }
346
-
347
192
  /**
348
193
  * Processes the provided module.
349
194
  * @param {NormalModule} module the current module
@@ -464,16 +309,13 @@ class CssGenerator extends Generator {
464
309
  case JAVASCRIPT_TYPE: {
465
310
  const compilation = generateContext.runtimeTemplate.compilation;
466
311
  const devtool = compilation.options.devtool;
467
- const isCssModule = /** @type {BuildMeta} */ (module.buildMeta)
312
+ const isCssModule = /** @type {CssModuleBuildMeta} */ (module.buildMeta)
468
313
  .isCssModule;
469
314
 
470
315
  const generateContentCode = () => {
471
316
  switch (exportType) {
472
317
  case "style": {
473
- const cssSource = this._generateContentSource(
474
- module,
475
- generateContext
476
- );
318
+ const cssSource = this._renderCss(module, generateContext);
477
319
  if (!cssSource) return "";
478
320
 
479
321
  generateContext.runtimeRequirements.add(
@@ -485,14 +327,16 @@ class CssGenerator extends Generator {
485
327
  if (generateContext.concatenationScope) {
486
328
  return new ConcatSource(
487
329
  `__webpack_css_styles__.push([${JSON.stringify(moduleId)}, `,
488
- this._cssToJsLiteral(cssSource, devtool),
330
+ this._cssToJsLiteral(cssSource, devtool, generateContext),
489
331
  "]);"
490
332
  );
491
333
  }
492
334
 
493
335
  return new ConcatSource(
494
- `${RuntimeGlobals.cssInjectStyle}(${JSON.stringify(moduleId)}, `,
495
- this._cssToJsLiteral(cssSource, devtool),
336
+ `${RuntimeGlobals.cssInjectStyle}(${JSON.stringify(
337
+ moduleId
338
+ )}, `,
339
+ this._cssToJsLiteral(cssSource, devtool, generateContext),
496
340
  ");"
497
341
  );
498
342
  }
@@ -504,7 +348,7 @@ class CssGenerator extends Generator {
504
348
  const generateImportCode = () => {
505
349
  switch (exportType) {
506
350
  case "style": {
507
- return this._generateImportSideEffects(module, generateContext)
351
+ return this._generateImportExpressions(module, generateContext)
508
352
  .map((expr) => `${expr};`)
509
353
  .join("\n");
510
354
  }
@@ -513,31 +357,6 @@ class CssGenerator extends Generator {
513
357
  }
514
358
  };
515
359
  const generateExportCode = () => {
516
- /** @returns {Source} generated CSS text as JS expression */
517
- const generateCssText = () => {
518
- const cssSource = this._generateMergedContentSource(
519
- module,
520
- generateContext,
521
- new Set()
522
- );
523
-
524
- let jsLiteral = cssSource
525
- ? this._cssToJsLiteral(cssSource, devtool)
526
- : new RawSource('""');
527
-
528
- const effectiveCharset =
529
- exportType === "css-style-sheet" || exportType === "text"
530
- ? this._getEffectiveCharset(module, generateContext.moduleGraph)
531
- : undefined;
532
- if (effectiveCharset !== undefined) {
533
- jsLiteral = new ConcatSource(
534
- `'@charset "${effectiveCharset}";\\n' + `,
535
- jsLiteral
536
- );
537
- }
538
-
539
- return jsLiteral;
540
- };
541
360
  /**
542
361
  * Generates js default export.
543
362
  * @returns {Source | null} the default export
@@ -545,21 +364,33 @@ class CssGenerator extends Generator {
545
364
  const generateJSDefaultExport = () => {
546
365
  switch (exportType) {
547
366
  case "text": {
548
- return generateCssText();
367
+ return this._generateCssText(module, generateContext, true);
549
368
  }
550
369
  case "css-style-sheet": {
551
- // Build a constructable stylesheet from the statically
552
- // merged CSS text. The merged literal carries a single
553
- // inline source map covering every contributing module.
554
- const fnPrefix =
555
- generateContext.runtimeTemplate.supportsArrowFunction()
556
- ? "() => {\n"
557
- : "function() {\n";
558
- const constOrVar =
559
- generateContext.runtimeTemplate.renderConst();
370
+ const rt = generateContext.runtimeTemplate;
371
+ const fnPrefix = rt.supportsArrowFunction()
372
+ ? "() => {\n"
373
+ : "function() {\n";
374
+ const constOrVar = rt.renderConst();
375
+ const fallback =
376
+ "{ cssText: css, replaceSync: function(value) { this.cssText = value; } }";
377
+ if (rt.compilation.compiler.platform.node === true) {
378
+ return new ConcatSource(
379
+ `(${fnPrefix}${constOrVar} css = `,
380
+ this._generateCssText(module, generateContext, true),
381
+ `;\nreturn ${fallback};\n})()`
382
+ );
383
+ }
384
+ if (rt.isUniversalTarget()) {
385
+ return new ConcatSource(
386
+ `(${fnPrefix}${constOrVar} css = `,
387
+ this._generateCssText(module, generateContext, true),
388
+ `;\nif (typeof CSSStyleSheet === 'undefined') return ${fallback};\n${constOrVar} sheet = new CSSStyleSheet();\nsheet.replaceSync(css);\nreturn sheet;\n})()`
389
+ );
390
+ }
560
391
  return new ConcatSource(
561
392
  `(${fnPrefix}${constOrVar} sheet = new CSSStyleSheet();\nsheet.replaceSync(`,
562
- generateCssText(),
393
+ this._generateCssText(module, generateContext, true),
563
394
  ");\nreturn sheet;\n})()"
564
395
  );
565
396
  }
@@ -571,7 +402,7 @@ class CssGenerator extends Generator {
571
402
  /** @type {Source | null} */
572
403
  const defaultExport = generateJSDefaultExport();
573
404
 
574
- /** @type {BuildInfo} */
405
+ /** @type {CssModuleBuildInfo} */
575
406
  (module.buildInfo).cssData = cssData;
576
407
 
577
408
  // Required for HMR
@@ -588,11 +419,15 @@ class CssGenerator extends Generator {
588
419
  /** @type {Set<string>} */
589
420
  const usedIdentifiers = new Set();
590
421
  const { RESERVED_IDENTIFIER } = getPropertyName();
422
+ const exportsInfo =
423
+ generateContext.moduleGraph.getExportsInfo(module);
591
424
 
592
425
  if (defaultExport) {
593
- const usedName = generateContext.moduleGraph
594
- .getExportInfo(module, "default")
595
- .getUsedName("default", generateContext.runtime);
426
+ const usedName = /** @type {string | false} */ (
427
+ exportsInfo
428
+ .getExportInfo("default")
429
+ .getUsedName("default", generateContext.runtime)
430
+ );
596
431
  if (usedName) {
597
432
  let identifier = Template.toIdentifier(usedName);
598
433
  if (RESERVED_IDENTIFIER.has(identifier)) {
@@ -612,9 +447,11 @@ class CssGenerator extends Generator {
612
447
  }
613
448
 
614
449
  for (const [name, v] of cssData.exports) {
615
- const usedName = generateContext.moduleGraph
616
- .getExportInfo(module, name)
617
- .getUsedName(name, generateContext.runtime);
450
+ const usedName = /** @type {string | false} */ (
451
+ exportsInfo
452
+ .getExportInfo(name)
453
+ .getUsedName(name, generateContext.runtime)
454
+ );
618
455
  if (!usedName) {
619
456
  continue;
620
457
  }
@@ -634,7 +471,9 @@ class CssGenerator extends Generator {
634
471
  identifier
635
472
  );
636
473
  source.add(
637
- `${generateContext.runtimeTemplate.renderConst()} ${identifier} = ${JSON.stringify(v)};\n`
474
+ `${generateContext.runtimeTemplate.renderConst()} ${identifier} = ${JSON.stringify(
475
+ v
476
+ )};\n`
638
477
  );
639
478
  }
640
479
  return source;
@@ -704,7 +543,6 @@ class CssGenerator extends Generator {
704
543
  source.add("\n");
705
544
  }
706
545
  }
707
- // For link-type modules without any JS emit, skip source wrapping
708
546
  if (
709
547
  exportType === "link" &&
710
548
  !isCssModule &&
@@ -718,9 +556,6 @@ class CssGenerator extends Generator {
718
556
  compilation.requestShortener
719
557
  );
720
558
 
721
- // When per-export source positions are available, emit a
722
- // SourceMapSource mapping each export line back to its CSS
723
- // selector; otherwise fall back to OriginalSource.
724
559
  if (
725
560
  /** @type {ExportLocsMap} */
726
561
  (cssData.exportLocs).size > 0
@@ -740,42 +575,14 @@ class CssGenerator extends Generator {
740
575
  return new OriginalSource(generatedJs, sourceName);
741
576
  }
742
577
  case CSS_TYPE: {
743
- if (!(this._exportsOnly || (exportType && exportType !== "link"))) {
578
+ if (!(this._exportsOnly || exportType !== "link")) {
744
579
  generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
745
580
  }
746
581
 
747
582
  return InitFragment.addToSource(source, initFragments, generateContext);
748
583
  }
749
- case CSS_TEXT_TYPE: {
750
- // The merged CSS text — what consumers like
751
- // `HtmlInlineStyleDependency.Template` need when they want to
752
- // drop the processed CSS straight into an inline `<style>`
753
- // tag. Mirrors the JS-side `generateCssText()` (charset
754
- // prefix included), without the JS string-literal wrapper.
755
- const cssSource = this._generateMergedContentSource(
756
- module,
757
- generateContext,
758
- new Set()
759
- );
760
-
761
- const effectiveCharset = this._getEffectiveCharset(
762
- module,
763
- generateContext.moduleGraph
764
- );
765
- const charsetPrefix =
766
- effectiveCharset !== undefined
767
- ? `@charset "${effectiveCharset}";\n`
768
- : "";
769
-
770
- if (!cssSource) {
771
- return charsetPrefix
772
- ? new RawSource(charsetPrefix)
773
- : new RawSource("");
774
- }
775
- return charsetPrefix
776
- ? new ConcatSource(charsetPrefix, cssSource)
777
- : cssSource;
778
- }
584
+ case CSS_TEXT_TYPE:
585
+ return this._generateCssText(module, generateContext, false);
779
586
  default:
780
587
  return null;
781
588
  }
@@ -814,10 +621,12 @@ class CssGenerator extends Generator {
814
621
  return JAVASCRIPT_TYPES;
815
622
  }
816
623
 
817
- const sourceTypes = new Set();
624
+ let hasJs = false;
625
+ let hasCssText = false;
818
626
  const connections = this._moduleGraph.getIncomingConnections(module);
819
627
 
820
628
  for (const connection of connections) {
629
+ if (hasJs && hasCssText) break;
821
630
  if (
822
631
  exportType === "link" &&
823
632
  connection.dependency instanceof CssImportDependency
@@ -825,22 +634,17 @@ class CssGenerator extends Generator {
825
634
  continue;
826
635
  }
827
636
 
828
- // when no hmr required, css module js output contains no sideEffects at all
829
- // js sideeffect connection doesn't require js type output
830
637
  if (connection.dependency instanceof HarmonyImportSideEffectDependency) {
831
638
  continue;
832
639
  }
833
640
 
834
- // Inline `<style>` blocks in HTML modules read the merged CSS
835
- // text directly via the `css-text` source type — they don't go
836
- // through the JS-string wrapper that other consumers use.
837
- // Matched by dependency category so the CSS package doesn't
838
- // have to import HtmlInlineStyleDependency.
641
+ // HTML inline styles consume CSS_TEXT_TYPE directly.
839
642
  if (
840
643
  connection.dependency &&
841
- connection.dependency.category === "html-style"
644
+ (connection.dependency.category === "html-style" ||
645
+ connection.dependency.category === "html-style-attribute")
842
646
  ) {
843
- sourceTypes.add(CSS_TEXT_TYPE);
647
+ hasCssText = true;
844
648
  continue;
845
649
  }
846
650
 
@@ -848,38 +652,36 @@ class CssGenerator extends Generator {
848
652
  continue;
849
653
  }
850
654
 
851
- if (connection.originModule.type.split("/")[0] !== CSS_TYPE) {
852
- sourceTypes.add(JAVASCRIPT_TYPE);
655
+ if (!connection.originModule.type.startsWith(CSS_TYPE_PREFIX)) {
656
+ hasJs = true;
853
657
  } else {
854
658
  const originModule = /** @type {CssModule} */ connection.originModule;
855
- const originExportType = /** @type {CssModule} */ (originModule)
856
- .exportType;
857
- if (
858
- /** @type {boolean} */ (
859
- originExportType && originExportType !== "link"
860
- )
861
- ) {
862
- sourceTypes.add(JAVASCRIPT_TYPE);
659
+ const originExportType =
660
+ /** @type {CssModule} */ (originModule).exportType || "link";
661
+ if (originExportType !== "link") {
662
+ hasJs = true;
863
663
  }
864
664
  }
865
665
  }
866
- if (
867
- this._exportsOnly ||
868
- /** @type {boolean} */ (exportType && exportType !== "link")
869
- ) {
870
- const hasJs = sourceTypes.has(JAVASCRIPT_TYPE);
871
- const hasCssText = sourceTypes.has(CSS_TEXT_TYPE);
666
+ if (this._exportsOnly || exportType !== "link") {
872
667
  if (hasJs && hasCssText) return JAVASCRIPT_AND_CSS_TEXT_TYPES;
873
668
  if (hasJs) return JAVASCRIPT_TYPES;
874
669
  if (hasCssText) return CSS_TEXT_TYPES;
875
- return new Set();
670
+ return NO_TYPES;
876
671
  }
877
- if (sourceTypes.has(JAVASCRIPT_TYPE)) {
672
+ if (hasJs) {
878
673
  return JAVASCRIPT_AND_CSS_TYPES;
879
674
  }
880
675
  return CSS_TYPES;
881
676
  }
882
677
 
678
+ /**
679
+ * @returns {boolean} whether getTypes() depends on the module's incoming connections
680
+ */
681
+ getTypesDependOnIncomingConnections() {
682
+ return true;
683
+ }
684
+
883
685
  /**
884
686
  * Returns the estimated size for the requested source type.
885
687
  * @param {NormalModule} module the module
@@ -889,12 +691,15 @@ class CssGenerator extends Generator {
889
691
  getSize(module, type) {
890
692
  switch (type) {
891
693
  case JAVASCRIPT_TYPE: {
892
- const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData;
694
+ const cssData = /** @type {CssModuleBuildInfo} */ (module.buildInfo)
695
+ .cssData;
893
696
  if (!cssData) {
894
697
  return 42;
895
698
  }
896
699
  if (cssData.exports.size === 0) {
897
- if (/** @type {BuildMeta} */ (module.buildMeta).isCssModule) {
700
+ if (
701
+ /** @type {CssModuleBuildMeta} */ (module.buildMeta).isCssModule
702
+ ) {
898
703
  return 42;
899
704
  }
900
705
  return 0;
@@ -909,6 +714,7 @@ class CssGenerator extends Generator {
909
714
 
910
715
  return stringifiedExports.length + 42;
911
716
  }
717
+ case CSS_TEXT_TYPE:
912
718
  case CSS_TYPE: {
913
719
  const originalSource = module.originalSource();
914
720
 
@@ -932,6 +738,226 @@ class CssGenerator extends Generator {
932
738
  hash.update(/** @type {boolean} */ (this._esModule).toString());
933
739
  hash.update(/** @type {boolean} */ (this._exportsOnly).toString());
934
740
  }
741
+
742
+ /**
743
+ * Resolve the effective `@charset` by walking text imports.
744
+ * @param {NormalModule} module the module
745
+ * @param {ModuleGraph} moduleGraph module graph
746
+ * @param {WeakSet<NormalModule>=} visited cycle guard
747
+ * @returns {string | undefined} the effective charset
748
+ */
749
+ _getEffectiveCharset(module, moduleGraph, visited = new WeakSet()) {
750
+ if (!module || visited.has(module)) return undefined;
751
+ const exportType = /** @type {CssModule} */ (module).exportType;
752
+ if (exportType !== "text" && exportType !== "css-style-sheet") {
753
+ return undefined;
754
+ }
755
+ visited.add(module);
756
+ const own =
757
+ module.buildInfo &&
758
+ /** @type {CssModuleBuildInfo} */ (module.buildInfo).charset;
759
+ if (own !== undefined) return own;
760
+ if (exportType !== "text") return undefined;
761
+ for (const dep of module.dependencies) {
762
+ if (dep instanceof CssImportDependency) {
763
+ const depModule = /** @type {NormalModule} */ (
764
+ moduleGraph.getModule(dep)
765
+ );
766
+ const inherited = this._getEffectiveCharset(
767
+ depModule,
768
+ moduleGraph,
769
+ visited
770
+ );
771
+ if (inherited !== undefined) return inherited;
772
+ }
773
+ }
774
+ return undefined;
775
+ }
776
+
777
+ /**
778
+ * Generate JS expressions for `@import` side effects (`style` exportType only).
779
+ * @param {NormalModule} module the module to generate CSS text for
780
+ * @param {GenerateContext} generateContext the generate context
781
+ * @returns {string[]} JS expressions, one per `@import` dependency
782
+ */
783
+ _generateImportExpressions(module, generateContext) {
784
+ const { moduleGraph, concatenationScope } = generateContext;
785
+ const parts = [];
786
+
787
+ for (const dep of module.dependencies) {
788
+ if (!(dep instanceof CssImportDependency)) continue;
789
+ const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
790
+ if (concatenationScope && concatenationScope.isModuleInScope(depModule)) {
791
+ continue;
792
+ }
793
+ parts.push(
794
+ generateContext.runtimeTemplate.moduleExports({
795
+ module: depModule,
796
+ chunkGraph: generateContext.chunkGraph,
797
+ request: depModule.userRequest,
798
+ weak: false,
799
+ runtimeRequirements: generateContext.runtimeRequirements
800
+ })
801
+ );
802
+ }
803
+
804
+ return parts;
805
+ }
806
+
807
+ /**
808
+ * Recursively merge `@import`'d CSS into a single Source (text/css-style-sheet only).
809
+ * @param {NormalModule} module the module to render
810
+ * @param {GenerateContext} generateContext the generate context
811
+ * @param {Set<NormalModule>} ancestors modules on the current path (cycle guard)
812
+ * @returns {Source | null} merged CSS source, or null when the module has no content
813
+ */
814
+ _renderMergedCss(module, generateContext, ancestors) {
815
+ if (ancestors.has(module)) return null;
816
+ ancestors.add(module);
817
+ try {
818
+ const { moduleGraph } = generateContext;
819
+ /** @type {Source[]} */
820
+ const parts = [];
821
+
822
+ for (const dep of module.dependencies) {
823
+ if (!(dep instanceof CssImportDependency)) continue;
824
+ const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
825
+ if (!depModule) continue;
826
+ const depExportType = depModule.exportType;
827
+ if (depExportType !== "text" && depExportType !== "css-style-sheet") {
828
+ continue;
829
+ }
830
+ const depMerged = this._renderMergedCss(
831
+ depModule,
832
+ generateContext,
833
+ ancestors
834
+ );
835
+ if (depMerged) parts.push(depMerged);
836
+ }
837
+
838
+ const own = this._renderCss(module, generateContext);
839
+ if (own) parts.push(own);
840
+
841
+ if (parts.length === 0) return null;
842
+ if (parts.length === 1) return parts[0];
843
+ return new ConcatSource(...parts);
844
+ } finally {
845
+ ancestors.delete(module);
846
+ }
847
+ }
848
+
849
+ /**
850
+ * Generate CSS source for the current module
851
+ * @param {NormalModule} module the module to generate CSS source for
852
+ * @param {GenerateContext} generateContext the generate context
853
+ * @returns {Source | null} the CSS source
854
+ */
855
+ _renderCss(module, generateContext) {
856
+ const moduleSourceContent = /** @type {Source} */ (
857
+ this.generate(module, {
858
+ ...generateContext,
859
+ type: CSS_TYPE
860
+ })
861
+ );
862
+
863
+ if (!moduleSourceContent) {
864
+ return null;
865
+ }
866
+
867
+ const compilation = generateContext.runtimeTemplate.compilation;
868
+ const undoPath = "";
869
+
870
+ const CssModulesPlugin = getCssModulesPlugin();
871
+ const hooks = CssModulesPlugin.getCompilationHooks(compilation);
872
+ return CssModulesPlugin.renderModule(
873
+ /** @type {CssModule} */ (module),
874
+ {
875
+ undoPath,
876
+ moduleSourceContent,
877
+ moduleFactoryCache: this._moduleFactoryCache,
878
+ runtimeTemplate: generateContext.runtimeTemplate
879
+ },
880
+ hooks
881
+ );
882
+ }
883
+
884
+ /**
885
+ * Convert a CSS Source into a JS string literal, splicing `__webpack_require__.h()` for `[fullhash]` placeholders.
886
+ * @param {Source} cssSource the CSS source
887
+ * @param {import("../../declarations/WebpackOptions").DevTool | undefined} devtool the devtool option
888
+ * @param {GenerateContext} generateContext the generate context
889
+ * @returns {Source} a Source representing a JS string literal
890
+ */
891
+ _cssToJsLiteral(cssSource, devtool, generateContext) {
892
+ const { source, map } = cssSource.sourceAndMap();
893
+ let content = /** @type {string} */ (source);
894
+ if (map) {
895
+ const inlineMap =
896
+ typeof devtool === "string" && devtool.includes("nosources")
897
+ ? { ...map, sourcesContent: undefined }
898
+ : map;
899
+ const base64Map = Buffer.from(JSON.stringify(inlineMap), "utf8").toString(
900
+ "base64"
901
+ );
902
+ const trailingNewline = content.endsWith("\n") ? "" : "\n";
903
+ content += `${trailingNewline}/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}*/`;
904
+ }
905
+
906
+ if (!content.includes(PUBLIC_PATH_FULL_HASH)) {
907
+ return new RawSource(JSON.stringify(content));
908
+ }
909
+
910
+ const result = new ConcatSource();
911
+ let last = 0;
912
+ walkFullHashPlaceholders(content, (start, end, length) => {
913
+ result.add(JSON.stringify(content.slice(last, start)));
914
+ result.add(
915
+ length === 0
916
+ ? ` + ${RuntimeGlobals.getFullHash}() + `
917
+ : ` + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + `
918
+ );
919
+ last = end;
920
+ });
921
+
922
+ result.add(JSON.stringify(content.slice(last)));
923
+ generateContext.runtimeRequirements.add(RuntimeGlobals.getFullHash);
924
+ return result;
925
+ }
926
+
927
+ /**
928
+ * Generate the merged CSS text for a module, optionally wrapped as a
929
+ * JS string literal for embedding in JavaScript output.
930
+ * @param {NormalModule} module the module
931
+ * @param {GenerateContext} generateContext the generate context
932
+ * @param {boolean} asJsLiteral wrap the result as a JS string literal
933
+ * @returns {Source} the CSS text source
934
+ */
935
+ _generateCssText(module, generateContext, asJsLiteral) {
936
+ const cssSource = this._renderMergedCss(module, generateContext, new Set());
937
+ const effectiveCharset = this._getEffectiveCharset(
938
+ module,
939
+ generateContext.moduleGraph
940
+ );
941
+
942
+ let result;
943
+ if (effectiveCharset !== undefined) {
944
+ const prefix = `@charset "${effectiveCharset}";\n`;
945
+ result = cssSource
946
+ ? new ConcatSource(prefix, cssSource)
947
+ : new RawSource(prefix);
948
+ } else {
949
+ result = cssSource;
950
+ }
951
+
952
+ if (asJsLiteral) {
953
+ const devtool =
954
+ generateContext.runtimeTemplate.compilation.options.devtool;
955
+ return result
956
+ ? this._cssToJsLiteral(result, devtool, generateContext)
957
+ : new RawSource('""');
958
+ }
959
+ return result || new RawSource("");
960
+ }
935
961
  }
936
962
 
937
963
  module.exports = CssGenerator;