webpack 5.106.1 → 5.107.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 (600) hide show
  1. package/README.md +2 -2
  2. package/lib/APIPlugin.js +4 -2
  3. package/lib/AsyncDependenciesBlock.js +3 -0
  4. package/lib/AutomaticPrefetchPlugin.js +6 -1
  5. package/lib/BannerPlugin.js +10 -1
  6. package/lib/Cache.js +27 -5
  7. package/lib/CacheFacade.js +26 -0
  8. package/lib/Chunk.js +46 -0
  9. package/lib/ChunkGraph.js +111 -0
  10. package/lib/ChunkGroup.js +57 -13
  11. package/lib/ChunkTemplate.js +9 -0
  12. package/lib/CleanPlugin.js +14 -1
  13. package/lib/CodeGenerationResults.js +19 -0
  14. package/lib/CompatibilityPlugin.js +23 -8
  15. package/lib/Compilation.js +161 -27
  16. package/lib/Compiler.js +41 -17
  17. package/lib/ConcatenationScope.js +24 -1
  18. package/lib/ConditionalInitFragment.js +6 -0
  19. package/lib/ConstPlugin.js +4 -1
  20. package/lib/ContextExclusionPlugin.js +2 -1
  21. package/lib/ContextModule.js +14 -2
  22. package/lib/ContextModuleFactory.js +10 -0
  23. package/lib/ContextReplacementPlugin.js +4 -1
  24. package/lib/DefinePlugin.js +22 -9
  25. package/lib/DependenciesBlock.js +6 -1
  26. package/lib/Dependency.js +48 -4
  27. package/lib/DependencyTemplate.js +7 -1
  28. package/lib/DependencyTemplates.js +4 -0
  29. package/lib/DotenvPlugin.js +3 -0
  30. package/lib/DynamicEntryPlugin.js +3 -1
  31. package/lib/EntryOptionPlugin.js +3 -0
  32. package/lib/EntryPlugin.js +2 -1
  33. package/lib/Entrypoint.js +4 -0
  34. package/lib/EnvironmentPlugin.js +3 -2
  35. package/lib/ErrorHelpers.js +7 -0
  36. package/lib/EvalDevToolModulePlugin.js +3 -1
  37. package/lib/EvalSourceMapDevToolPlugin.js +11 -10
  38. package/lib/ExportsInfo.js +56 -2
  39. package/lib/ExportsInfoApiPlugin.js +2 -1
  40. package/lib/ExternalModule.js +114 -15
  41. package/lib/ExternalModuleFactoryPlugin.js +15 -0
  42. package/lib/ExternalsPlugin.js +2 -1
  43. package/lib/FileSystemInfo.js +291 -71
  44. package/lib/FlagAllModulesAsUsedPlugin.js +2 -1
  45. package/lib/FlagDependencyExportsPlugin.js +4 -1
  46. package/lib/FlagDependencyUsagePlugin.js +5 -1
  47. package/lib/FlagEntryExportAsUsedPlugin.js +2 -1
  48. package/lib/Generator.js +16 -3
  49. package/lib/HotModuleReplacementPlugin.js +35 -9
  50. package/lib/IgnorePlugin.js +4 -2
  51. package/lib/IgnoreWarningsPlugin.js +2 -1
  52. package/lib/InitFragment.js +10 -0
  53. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  54. package/lib/LibraryTemplatePlugin.js +2 -1
  55. package/lib/LoaderOptionsPlugin.js +3 -1
  56. package/lib/LoaderTargetPlugin.js +2 -1
  57. package/lib/MainTemplate.js +15 -0
  58. package/lib/ManifestPlugin.js +9 -2
  59. package/lib/Module.js +101 -19
  60. package/lib/ModuleFactory.js +6 -1
  61. package/lib/ModuleFilenameHelpers.js +3 -0
  62. package/lib/ModuleGraph.js +66 -0
  63. package/lib/ModuleGraphConnection.js +9 -0
  64. package/lib/ModuleInfoHeaderPlugin.js +5 -0
  65. package/lib/ModuleSourceTypeConstants.js +32 -1
  66. package/lib/ModuleTemplate.js +8 -0
  67. package/lib/ModuleTypeConstants.js +12 -3
  68. package/lib/MultiCompiler.js +30 -2
  69. package/lib/MultiStats.js +8 -0
  70. package/lib/MultiWatching.js +3 -0
  71. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  72. package/lib/NodeStuffPlugin.js +11 -2
  73. package/lib/NormalModule.js +43 -33
  74. package/lib/NormalModuleFactory.js +35 -2
  75. package/lib/NormalModuleReplacementPlugin.js +1 -1
  76. package/lib/NullFactory.js +1 -0
  77. package/lib/OptionsApply.js +1 -0
  78. package/lib/Parser.js +3 -1
  79. package/lib/PlatformPlugin.js +2 -1
  80. package/lib/PrefetchPlugin.js +2 -1
  81. package/lib/ProgressPlugin.js +158 -68
  82. package/lib/ProvidePlugin.js +3 -1
  83. package/lib/RawModule.js +12 -0
  84. package/lib/RecordIdsPlugin.js +8 -0
  85. package/lib/RequestShortener.js +8 -0
  86. package/lib/ResolverFactory.js +5 -0
  87. package/lib/RuntimeGlobals.js +6 -5
  88. package/lib/RuntimeModule.js +22 -7
  89. package/lib/RuntimePlugin.js +13 -0
  90. package/lib/RuntimeTemplate.js +35 -1
  91. package/lib/SelfModuleFactory.js +2 -0
  92. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
  93. package/lib/SourceMapDevToolPlugin.js +3 -1
  94. package/lib/Stats.js +5 -0
  95. package/lib/Template.js +20 -0
  96. package/lib/TemplatedPathPlugin.js +10 -3
  97. package/lib/UseStrictPlugin.js +2 -1
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +71 -3
  99. package/lib/WarnDeprecatedOptionPlugin.js +2 -2
  100. package/lib/WarnNoModeSetPlugin.js +17 -2
  101. package/lib/WatchIgnorePlugin.js +4 -1
  102. package/lib/Watching.js +16 -3
  103. package/lib/WebpackError.js +3 -74
  104. package/lib/WebpackIsIncludedPlugin.js +3 -1
  105. package/lib/WebpackOptionsApply.js +14 -1
  106. package/lib/WebpackOptionsDefaulter.js +1 -0
  107. package/lib/asset/AssetBytesGenerator.js +12 -2
  108. package/lib/asset/AssetBytesParser.js +1 -0
  109. package/lib/asset/AssetGenerator.js +42 -10
  110. package/lib/asset/AssetModulesPlugin.js +7 -2
  111. package/lib/asset/AssetParser.js +2 -0
  112. package/lib/asset/AssetSourceGenerator.js +12 -2
  113. package/lib/asset/AssetSourceParser.js +1 -0
  114. package/lib/asset/RawDataUrlModule.js +11 -0
  115. package/lib/async-modules/AsyncModuleHelpers.js +1 -0
  116. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  117. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  118. package/lib/buildChunkGraph.js +19 -6
  119. package/lib/cache/AddBuildDependenciesPlugin.js +2 -1
  120. package/lib/cache/AddManagedPathsPlugin.js +2 -1
  121. package/lib/cache/IdleFileCachePlugin.js +2 -1
  122. package/lib/cache/MemoryCachePlugin.js +1 -1
  123. package/lib/cache/MemoryWithGcCachePlugin.js +3 -1
  124. package/lib/cache/PackFileCacheStrategy.js +33 -4
  125. package/lib/cache/ResolverCachePlugin.js +10 -1
  126. package/lib/cache/getLazyHashedEtag.js +4 -0
  127. package/lib/cache/mergeEtags.js +2 -0
  128. package/lib/cli.js +33 -1
  129. package/lib/config/browserslistTargetHandler.js +2 -0
  130. package/lib/config/defaults.js +232 -12
  131. package/lib/config/normalization.js +15 -1
  132. package/lib/config/target.js +11 -0
  133. package/lib/container/ContainerEntryDependency.js +2 -0
  134. package/lib/container/ContainerEntryModule.js +12 -0
  135. package/lib/container/ContainerEntryModuleFactory.js +1 -0
  136. package/lib/container/ContainerExposedDependency.js +4 -0
  137. package/lib/container/ContainerPlugin.js +2 -1
  138. package/lib/container/ContainerReferencePlugin.js +2 -1
  139. package/lib/container/FallbackDependency.js +4 -0
  140. package/lib/container/FallbackItemDependency.js +1 -0
  141. package/lib/container/FallbackModule.js +12 -0
  142. package/lib/container/FallbackModuleFactory.js +1 -0
  143. package/lib/container/ModuleFederationPlugin.js +3 -1
  144. package/lib/container/RemoteModule.js +13 -0
  145. package/lib/container/RemoteRuntimeModule.js +1 -0
  146. package/lib/container/RemoteToExternalDependency.js +1 -0
  147. package/lib/container/options.js +7 -0
  148. package/lib/css/CssGenerator.js +336 -100
  149. package/lib/css/CssInjectStyleRuntimeModule.js +45 -42
  150. package/lib/css/CssLoadingRuntimeModule.js +23 -4
  151. package/lib/{CssModule.js → css/CssModule.js} +21 -15
  152. package/lib/css/CssModulesPlugin.js +235 -89
  153. package/lib/css/CssParser.js +616 -261
  154. package/lib/css/walkCssTokens.js +179 -2
  155. package/lib/debug/ProfilingPlugin.js +19 -1
  156. package/lib/dependencies/AMDDefineDependency.js +7 -0
  157. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -0
  158. package/lib/dependencies/AMDPlugin.js +4 -1
  159. package/lib/dependencies/AMDRequireArrayDependency.js +6 -0
  160. package/lib/dependencies/AMDRequireContextDependency.js +3 -0
  161. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
  162. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +14 -1
  163. package/lib/dependencies/AMDRequireDependency.js +4 -0
  164. package/lib/dependencies/AMDRequireItemDependency.js +1 -0
  165. package/lib/dependencies/AMDRuntimeModules.js +3 -0
  166. package/lib/dependencies/CachedConstDependency.js +6 -1
  167. package/lib/dependencies/CommonJsDependencyHelpers.js +64 -0
  168. package/lib/dependencies/CommonJsExportRequireDependency.js +62 -10
  169. package/lib/dependencies/CommonJsExportsDependency.js +4 -0
  170. package/lib/dependencies/CommonJsExportsParserPlugin.js +9 -1
  171. package/lib/dependencies/CommonJsFullRequireDependency.js +36 -9
  172. package/lib/dependencies/CommonJsImportsParserPlugin.js +24 -3
  173. package/lib/dependencies/CommonJsPlugin.js +4 -1
  174. package/lib/dependencies/CommonJsRequireContextDependency.js +3 -0
  175. package/lib/dependencies/CommonJsRequireDependency.js +70 -4
  176. package/lib/dependencies/CommonJsSelfReferenceDependency.js +5 -0
  177. package/lib/dependencies/ConstDependency.js +6 -1
  178. package/lib/dependencies/ContextDependency.js +9 -2
  179. package/lib/dependencies/ContextDependencyHelpers.js +4 -1
  180. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  181. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  182. package/lib/dependencies/ContextElementDependency.js +4 -0
  183. package/lib/dependencies/CreateRequireParserPlugin.js +7 -1
  184. package/lib/dependencies/CreateScriptUrlDependency.js +4 -0
  185. package/lib/dependencies/CriticalDependencyWarning.js +2 -1
  186. package/lib/dependencies/CssIcssExportDependency.js +339 -66
  187. package/lib/dependencies/CssIcssImportDependency.js +53 -8
  188. package/lib/dependencies/CssIcssSymbolDependency.js +16 -4
  189. package/lib/dependencies/CssImportDependency.js +12 -0
  190. package/lib/dependencies/CssUrlDependency.js +32 -0
  191. package/lib/dependencies/DelegatedSourceDependency.js +1 -0
  192. package/lib/dependencies/DllEntryDependency.js +3 -0
  193. package/lib/dependencies/DynamicExports.js +5 -0
  194. package/lib/dependencies/EntryDependency.js +1 -0
  195. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  196. package/lib/dependencies/ExternalModuleDependency.js +5 -0
  197. package/lib/dependencies/ExternalModuleInitFragment.js +3 -0
  198. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +4 -0
  199. package/lib/dependencies/HarmonyAcceptDependency.js +6 -0
  200. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  201. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -0
  202. package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -1
  203. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -0
  204. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  205. package/lib/dependencies/HarmonyExportExpressionDependency.js +27 -14
  206. package/lib/dependencies/HarmonyExportHeaderDependency.js +4 -0
  207. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +143 -5
  208. package/lib/dependencies/HarmonyExportInitFragment.js +6 -0
  209. package/lib/dependencies/HarmonyExportSpecifierDependency.js +5 -0
  210. package/lib/dependencies/HarmonyExports.js +2 -0
  211. package/lib/dependencies/HarmonyImportDependency.js +21 -2
  212. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -1
  213. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -0
  214. package/lib/dependencies/HarmonyImportSpecifierDependency.js +18 -3
  215. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
  216. package/lib/dependencies/HarmonyModulesPlugin.js +4 -1
  217. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -0
  218. package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
  219. package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
  220. package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
  221. package/lib/dependencies/HtmlSourceDependency.js +127 -0
  222. package/lib/dependencies/ImportContextDependency.js +4 -0
  223. package/lib/dependencies/ImportDependency.js +5 -0
  224. package/lib/dependencies/ImportEagerDependency.js +2 -0
  225. package/lib/dependencies/ImportMetaContextDependency.js +1 -0
  226. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -1
  227. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  228. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  229. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  230. package/lib/dependencies/ImportMetaPlugin.js +6 -0
  231. package/lib/dependencies/ImportParserPlugin.js +9 -2
  232. package/lib/dependencies/ImportPhase.js +7 -3
  233. package/lib/dependencies/ImportPlugin.js +2 -1
  234. package/lib/dependencies/ImportWeakDependency.js +2 -0
  235. package/lib/dependencies/JsonExportsDependency.js +6 -1
  236. package/lib/dependencies/LoaderDependency.js +2 -0
  237. package/lib/dependencies/LoaderImportDependency.js +2 -0
  238. package/lib/dependencies/LoaderPlugin.js +4 -1
  239. package/lib/dependencies/LocalModule.js +4 -0
  240. package/lib/dependencies/LocalModuleDependency.js +4 -0
  241. package/lib/dependencies/LocalModulesHelpers.js +3 -0
  242. package/lib/dependencies/ModuleDecoratorDependency.js +7 -1
  243. package/lib/dependencies/ModuleDependency.js +7 -0
  244. package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
  245. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  246. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  247. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  248. package/lib/dependencies/ModuleInitFragmentDependency.js +4 -0
  249. package/lib/dependencies/NullDependency.js +2 -0
  250. package/lib/dependencies/PrefetchDependency.js +1 -0
  251. package/lib/dependencies/ProvidedDependency.js +6 -1
  252. package/lib/dependencies/PureExpressionDependency.js +7 -1
  253. package/lib/dependencies/RequireContextDependency.js +1 -0
  254. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -0
  255. package/lib/dependencies/RequireContextPlugin.js +2 -1
  256. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
  257. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -0
  258. package/lib/dependencies/RequireEnsureDependency.js +4 -0
  259. package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
  260. package/lib/dependencies/RequireEnsurePlugin.js +2 -1
  261. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  262. package/lib/dependencies/RequireIncludeDependency.js +2 -0
  263. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -1
  264. package/lib/dependencies/RequireIncludePlugin.js +2 -1
  265. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
  266. package/lib/dependencies/RequireResolveContextDependency.js +3 -0
  267. package/lib/dependencies/RequireResolveDependency.js +1 -0
  268. package/lib/dependencies/RequireResolveHeaderDependency.js +5 -0
  269. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
  270. package/lib/dependencies/StaticExportsDependency.js +3 -0
  271. package/lib/dependencies/SystemPlugin.js +5 -2
  272. package/lib/dependencies/SystemRuntimeModule.js +1 -0
  273. package/lib/dependencies/URLContextDependency.js +3 -0
  274. package/lib/dependencies/URLDependency.js +6 -0
  275. package/lib/dependencies/URLPlugin.js +2 -0
  276. package/lib/dependencies/UnsupportedDependency.js +4 -0
  277. package/lib/dependencies/WebAssemblyExportImportedDependency.js +4 -0
  278. package/lib/dependencies/WebAssemblyImportDependency.js +5 -2
  279. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -0
  280. package/lib/dependencies/WorkerDependency.js +6 -1
  281. package/lib/dependencies/WorkerPlugin.js +11 -3
  282. package/lib/dependencies/getFunctionExpression.js +1 -0
  283. package/lib/dependencies/processExportInfo.js +1 -0
  284. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +44 -31
  285. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +7 -4
  286. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +4 -3
  287. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +6 -5
  288. package/lib/{DllModule.js → dll/DllModule.js} +35 -24
  289. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
  290. package/lib/{DllPlugin.js → dll/DllPlugin.js} +8 -6
  291. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +23 -18
  292. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +13 -10
  293. package/lib/electron/ElectronTargetPlugin.js +2 -1
  294. package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
  295. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
  296. package/lib/errors/BuildCycleError.js +1 -1
  297. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  298. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  299. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
  300. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
  301. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
  302. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +11 -5
  303. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +6 -4
  304. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +4 -3
  305. package/lib/errors/JSONParseError.js +114 -0
  306. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +8 -5
  307. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
  308. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +5 -4
  309. package/lib/{ModuleError.js → errors/ModuleError.js} +7 -5
  310. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
  311. package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +3 -2
  312. package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +11 -6
  313. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +2 -1
  314. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +2 -1
  315. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +8 -5
  316. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +5 -4
  317. package/lib/errors/NonErrorEmittedError.js +28 -0
  318. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +8 -2
  319. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
  320. package/lib/errors/WebpackError.js +84 -0
  321. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  322. package/lib/esm/ModuleChunkFormatPlugin.js +5 -1
  323. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  324. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +5 -0
  325. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  326. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
  327. package/lib/hmr/LazyCompilationPlugin.js +20 -1
  328. package/lib/hmr/lazyCompilationBackend.js +2 -0
  329. package/lib/html/HtmlGenerator.js +379 -0
  330. package/lib/html/HtmlModulesPlugin.js +433 -0
  331. package/lib/html/HtmlParser.js +1489 -0
  332. package/lib/html/walkHtmlTokens.js +2733 -0
  333. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
  334. package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
  335. package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
  336. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  337. package/lib/ids/IdHelpers.js +22 -1
  338. package/lib/ids/NamedChunkIdsPlugin.js +3 -1
  339. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  340. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  341. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  342. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
  343. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
  344. package/lib/ids/SyncModuleIdsPlugin.js +3 -1
  345. package/lib/index.js +39 -15
  346. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
  347. package/lib/javascript/BasicEvaluatedExpression.js +4 -2
  348. package/lib/javascript/ChunkFormatHelpers.js +2 -1
  349. package/lib/javascript/ChunkHelpers.js +1 -0
  350. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  351. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -1
  352. package/lib/javascript/JavascriptGenerator.js +10 -0
  353. package/lib/javascript/JavascriptModulesPlugin.js +112 -9
  354. package/lib/javascript/JavascriptParser.js +360 -16
  355. package/lib/javascript/JavascriptParserHelpers.js +7 -1
  356. package/lib/javascript/StartupHelpers.js +5 -0
  357. package/lib/json/JsonData.js +5 -0
  358. package/lib/json/JsonGenerator.js +21 -0
  359. package/lib/json/JsonModulesPlugin.js +1 -1
  360. package/lib/json/JsonParser.js +14 -25
  361. package/lib/library/AbstractLibraryPlugin.js +17 -2
  362. package/lib/library/AmdLibraryPlugin.js +8 -0
  363. package/lib/library/AssignLibraryPlugin.js +16 -0
  364. package/lib/library/EnableLibraryPlugin.js +8 -2
  365. package/lib/library/ExportPropertyLibraryPlugin.js +9 -0
  366. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
  367. package/lib/library/JsonpLibraryPlugin.js +8 -0
  368. package/lib/library/ModuleLibraryPlugin.js +86 -1
  369. package/lib/library/SystemLibraryPlugin.js +8 -0
  370. package/lib/library/UmdLibraryPlugin.js +16 -0
  371. package/lib/logging/Logger.js +17 -0
  372. package/lib/logging/createConsoleLogger.js +7 -0
  373. package/lib/logging/runtime.js +2 -0
  374. package/lib/logging/truncateArgs.js +2 -0
  375. package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
  376. package/lib/node/NodeEnvironmentPlugin.js +7 -3
  377. package/lib/node/NodeSourcePlugin.js +1 -1
  378. package/lib/node/NodeTargetPlugin.js +2 -1
  379. package/lib/node/NodeTemplatePlugin.js +3 -1
  380. package/lib/node/NodeWatchFileSystem.js +2 -0
  381. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +3 -0
  382. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -1
  383. package/lib/node/ReadFileCompileWasmPlugin.js +4 -1
  384. package/lib/node/RequireChunkLoadingRuntimeModule.js +3 -0
  385. package/lib/node/nodeConsole.js +116 -64
  386. package/lib/optimize/AggressiveMergingPlugin.js +3 -1
  387. package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
  388. package/lib/optimize/ConcatenatedModule.js +62 -6
  389. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
  390. package/lib/optimize/FlagIncludedChunksPlugin.js +2 -1
  391. package/lib/optimize/InnerGraph.js +16 -1
  392. package/lib/optimize/InnerGraphPlugin.js +14 -2
  393. package/lib/optimize/LimitChunkCountPlugin.js +9 -0
  394. package/lib/optimize/MangleExportsPlugin.js +5 -1
  395. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
  396. package/lib/optimize/MinChunkSizePlugin.js +2 -1
  397. package/lib/optimize/MinMaxSizeWarning.js +5 -4
  398. package/lib/optimize/ModuleConcatenationPlugin.js +36 -8
  399. package/lib/optimize/RealContentHashPlugin.js +104 -26
  400. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  401. package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
  402. package/lib/optimize/RuntimeChunkPlugin.js +2 -1
  403. package/lib/optimize/SideEffectsFlagPlugin.js +118 -4
  404. package/lib/optimize/SplitChunksPlugin.js +50 -2
  405. package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
  406. package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
  407. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  408. package/lib/performance/SizeLimitsPlugin.js +8 -2
  409. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
  410. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +6 -0
  411. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
  412. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
  413. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  414. package/lib/rules/BasicEffectRulePlugin.js +3 -0
  415. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  416. package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
  417. package/lib/rules/RuleSetCompiler.js +18 -0
  418. package/lib/rules/UseEffectRulePlugin.js +10 -3
  419. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  420. package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -0
  421. package/lib/runtime/BaseUriRuntimeModule.js +1 -0
  422. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  423. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -0
  424. package/lib/runtime/CompatRuntimeModule.js +2 -0
  425. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -0
  426. package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
  427. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
  428. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -0
  429. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  430. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -0
  431. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  432. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
  433. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  434. package/lib/runtime/GlobalRuntimeModule.js +1 -0
  435. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -0
  436. package/lib/runtime/HelperRuntimeModule.js +5 -0
  437. package/lib/runtime/LoadScriptRuntimeModule.js +1 -0
  438. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +121 -13
  439. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -0
  440. package/lib/runtime/NonceRuntimeModule.js +1 -0
  441. package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -0
  442. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  443. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -0
  444. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
  445. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
  446. package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
  447. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  448. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  449. package/lib/runtime/SystemContextRuntimeModule.js +1 -0
  450. package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
  451. package/lib/schemes/DataUriPlugin.js +14 -2
  452. package/lib/schemes/FileUriPlugin.js +1 -1
  453. package/lib/schemes/HttpUriPlugin.js +43 -1
  454. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  455. package/lib/serialization/AggregateErrorSerializer.js +2 -0
  456. package/lib/serialization/ArraySerializer.js +2 -0
  457. package/lib/serialization/BinaryMiddleware.js +20 -1
  458. package/lib/serialization/DateObjectSerializer.js +2 -0
  459. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  460. package/lib/serialization/FileMiddleware.js +21 -0
  461. package/lib/serialization/MapObjectSerializer.js +2 -0
  462. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -0
  463. package/lib/serialization/ObjectMiddleware.js +23 -0
  464. package/lib/serialization/PlainObjectSerializer.js +7 -0
  465. package/lib/serialization/RegExpObjectSerializer.js +2 -0
  466. package/lib/serialization/Serializer.js +5 -0
  467. package/lib/serialization/SerializerMiddleware.js +14 -2
  468. package/lib/serialization/SetObjectSerializer.js +2 -0
  469. package/lib/serialization/SingleItemMiddleware.js +3 -0
  470. package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
  471. package/lib/sharing/ConsumeSharedModule.js +15 -0
  472. package/lib/sharing/ConsumeSharedPlugin.js +8 -3
  473. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -4
  474. package/lib/sharing/ProvideForSharedDependency.js +1 -0
  475. package/lib/sharing/ProvideSharedDependency.js +4 -0
  476. package/lib/sharing/ProvideSharedModule.js +12 -1
  477. package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
  478. package/lib/sharing/ProvideSharedPlugin.js +5 -2
  479. package/lib/sharing/SharePlugin.js +2 -1
  480. package/lib/sharing/ShareRuntimeModule.js +1 -0
  481. package/lib/sharing/resolveMatchedConfigs.js +4 -1
  482. package/lib/sharing/utils.js +8 -0
  483. package/lib/stats/DefaultStatsFactoryPlugin.js +58 -3
  484. package/lib/stats/DefaultStatsPresetPlugin.js +12 -2
  485. package/lib/stats/DefaultStatsPrinterPlugin.js +38 -2
  486. package/lib/stats/StatsFactory.js +13 -1
  487. package/lib/stats/StatsPrinter.js +7 -0
  488. package/lib/typescript/TypeScriptPlugin.js +210 -0
  489. package/lib/url/URLParserPlugin.js +8 -2
  490. package/lib/util/AppendOnlyStackedSet.js +15 -0
  491. package/lib/util/ArrayHelpers.js +1 -0
  492. package/lib/util/ArrayQueue.js +10 -5
  493. package/lib/util/AsyncQueue.js +22 -2
  494. package/lib/util/Hash.js +2 -2
  495. package/lib/util/IterableHelpers.js +3 -0
  496. package/lib/util/LazyBucketSortedSet.js +21 -0
  497. package/lib/util/LazySet.js +39 -0
  498. package/lib/util/LocConverter.js +53 -0
  499. package/lib/util/ParallelismFactorCalculator.js +1 -0
  500. package/lib/util/Queue.js +6 -3
  501. package/lib/util/Semaphore.js +14 -1
  502. package/lib/util/SetHelpers.js +3 -0
  503. package/lib/util/SortableSet.js +7 -1
  504. package/lib/util/StackedCacheMap.js +20 -3
  505. package/lib/util/StackedMap.js +45 -0
  506. package/lib/util/StringXor.js +1 -1
  507. package/lib/util/TupleQueue.js +7 -3
  508. package/lib/util/TupleSet.js +13 -0
  509. package/lib/util/URLAbsoluteSpecifier.js +1 -0
  510. package/lib/util/WeakTupleMap.js +33 -0
  511. package/lib/util/binarySearchBounds.js +1 -0
  512. package/lib/util/cleverMerge.js +19 -2
  513. package/lib/util/comparators.js +34 -3
  514. package/lib/util/compileBooleanMatcher.js +9 -0
  515. package/lib/util/concatenate.js +9 -3
  516. package/lib/util/conventions.js +46 -1
  517. package/lib/util/createMappings.js +118 -0
  518. package/lib/util/dataURL.js +1 -0
  519. package/lib/util/deprecation.js +19 -0
  520. package/lib/util/deterministicGrouping.js +20 -0
  521. package/lib/util/extractSourceMap.js +1 -0
  522. package/lib/util/extractUrlAndGlobal.js +1 -0
  523. package/lib/util/findGraphRoots.js +5 -0
  524. package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
  525. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +4 -1
  526. package/lib/util/fs.js +71 -8
  527. package/lib/util/generateDebugId.js +1 -0
  528. package/lib/util/hash/BatchedHash.js +1 -0
  529. package/lib/util/hash/BulkUpdateHash.js +1 -0
  530. package/lib/util/hash/hash-digest.js +8 -0
  531. package/lib/util/hash/md4.js +1 -1
  532. package/lib/util/hash/wasm-hash.js +5 -0
  533. package/lib/util/hash/xxhash64.js +1 -1
  534. package/lib/util/identifier.js +67 -0
  535. package/lib/util/internalSerializables.js +35 -19
  536. package/lib/util/magicComment.js +10 -6
  537. package/lib/util/makeSerializable.js +6 -0
  538. package/lib/util/memoize.js +2 -0
  539. package/lib/util/mimeTypes.js +176 -0
  540. package/lib/util/nonNumericOnlyHash.js +1 -0
  541. package/lib/util/parseJson.js +41 -0
  542. package/lib/util/processAsyncTree.js +8 -0
  543. package/lib/util/property.js +1 -0
  544. package/lib/util/registerExternalSerializer.js +20 -0
  545. package/lib/util/removeBOM.js +1 -0
  546. package/lib/util/runtime.js +32 -0
  547. package/lib/util/semver.js +15 -0
  548. package/lib/util/serialization.js +2 -0
  549. package/lib/util/smartGrouping.js +8 -0
  550. package/lib/util/source.js +23 -0
  551. package/lib/util/topologicalSort.js +69 -0
  552. package/lib/validateSchema.js +1 -0
  553. package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
  554. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +1 -0
  555. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -0
  556. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
  557. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -0
  558. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +12 -3
  559. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
  560. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +12 -1
  561. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +6 -3
  562. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -0
  563. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
  564. package/lib/wasm-sync/WebAssemblyGenerator.js +26 -1
  565. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +7 -3
  566. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
  567. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -1
  568. package/lib/wasm-sync/WebAssemblyParser.js +2 -0
  569. package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
  570. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -1
  571. package/lib/web/FetchCompileWasmPlugin.js +13 -1
  572. package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
  573. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  574. package/lib/web/JsonpTemplatePlugin.js +2 -1
  575. package/lib/webpack.js +13 -1
  576. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
  577. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -0
  578. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  579. package/package.json +31 -31
  580. package/schemas/WebpackOptions.check.js +1 -1
  581. package/schemas/WebpackOptions.json +161 -57
  582. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  583. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  584. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  585. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  586. package/schemas/plugins/ProgressPlugin.json +22 -0
  587. package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
  588. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  589. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  590. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  591. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  592. package/types.d.ts +5325 -353
  593. package/lib/CaseSensitiveModulesWarning.js +0 -72
  594. package/lib/GraphHelpers.js +0 -46
  595. package/lib/NoModeWarning.js +0 -23
  596. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
  597. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  598. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  599. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  600. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -7,6 +7,7 @@
7
7
 
8
8
  const {
9
9
  ConcatSource,
10
+ OriginalSource,
10
11
  RawSource,
11
12
  ReplaceSource,
12
13
  SourceMapSource
@@ -15,8 +16,11 @@ const { UsageState } = require("../ExportsInfo");
15
16
  const Generator = require("../Generator");
16
17
  const InitFragment = require("../InitFragment");
17
18
  const {
19
+ CSS_TEXT_TYPE,
20
+ CSS_TEXT_TYPES,
18
21
  CSS_TYPE,
19
22
  CSS_TYPES,
23
+ JAVASCRIPT_AND_CSS_TEXT_TYPES,
20
24
  JAVASCRIPT_AND_CSS_TYPES,
21
25
  JAVASCRIPT_TYPE,
22
26
  JAVASCRIPT_TYPES
@@ -26,6 +30,7 @@ const Template = require("../Template");
26
30
  const CssImportDependency = require("../dependencies/CssImportDependency");
27
31
  const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
28
32
 
33
+ const { encodeMappings } = require("../util/createMappings");
29
34
  const memoize = require("../util/memoize");
30
35
 
31
36
  /** @typedef {import("webpack-sources").Source} Source */
@@ -46,16 +51,77 @@ const memoize = require("../util/memoize");
46
51
  /** @typedef {import("../NormalModule")} NormalModule */
47
52
  /** @typedef {import("../util/Hash")} Hash */
48
53
  /** @typedef {import("./CssModulesPlugin").ModuleFactoryCacheEntry} ModuleFactoryCacheEntry */
49
- /** @typedef {import("../CssModule")} CssModule */
54
+ /** @typedef {import("./CssModule")} CssModule */
50
55
  /** @typedef {import("../Compilation")} Compilation */
51
56
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
52
57
  /** @typedef {import("../../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
53
58
 
59
+ /** @typedef {{ line: number, column: number }} SourcePosition */
60
+ /** @typedef {Map<string, SourcePosition>} ExportLocsMap */
61
+
54
62
  const getPropertyName = memoize(() => require("../util/property"));
55
63
  const getCssModulesPlugin = memoize(() => require("./CssModulesPlugin"));
56
64
 
65
+ /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
66
+
67
+ /**
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.
72
+ * @param {string} generatedJs the generated JS string
73
+ * @param {ExportLocsMap} exportLocs map of export names to CSS source location
74
+ * @param {string} cssContent original CSS source content
75
+ * @param {string} sourceName source identifier to use in the map
76
+ * @returns {RawSourceMap} a v3 RawSourceMap
77
+ */
78
+ const buildExportsSourceMap = (
79
+ generatedJs,
80
+ exportLocs,
81
+ cssContent,
82
+ sourceName
83
+ ) => {
84
+ const lines = generatedJs.split("\n");
85
+
86
+ const lineByExport = new Map();
87
+ 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;
93
+ }
94
+ }
95
+ }
96
+
97
+ /** @type {(import("../util/createMappings").LineMappings)[]} */
98
+ const perLine = lines.map(() => null);
99
+ for (const [exportName, genLine] of lineByExport) {
100
+ 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.
104
+ perLine[genLine] = {
105
+ generatedColumn: 0,
106
+ sourceIndex: 0,
107
+ originalLine: pos.line - 1,
108
+ originalColumn: pos.column
109
+ };
110
+ }
111
+
112
+ return {
113
+ version: 3,
114
+ file: "",
115
+ sources: [sourceName],
116
+ sourcesContent: [cssContent],
117
+ names: [],
118
+ mappings: encodeMappings(perLine)
119
+ };
120
+ };
121
+
57
122
  class CssGenerator extends Generator {
58
123
  /**
124
+ * Creates an instance of CssGenerator.
59
125
  * @param {CssModuleGeneratorOptions} options options
60
126
  * @param {ModuleGraph} moduleGraph the module graph
61
127
  */
@@ -70,6 +136,7 @@ class CssGenerator extends Generator {
70
136
  }
71
137
 
72
138
  /**
139
+ * Returns the reason this module cannot be concatenated, when one exists.
73
140
  * @param {NormalModule} module module for which the bailout reason should be determined
74
141
  * @param {ConcatenationBailoutReasonContext} context context
75
142
  * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
@@ -83,52 +150,134 @@ class CssGenerator extends Generator {
83
150
  }
84
151
 
85
152
  /**
86
- * Generate JavaScript code that requires and concatenates all CSS imports
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}.
87
195
  * @param {NormalModule} module the module to generate CSS text for
88
196
  * @param {GenerateContext} generateContext the generate context
89
- * @param {boolean} getDefaultExport whether to get the default export
90
- * @returns {{ expr: string, type: CssParserExportType }[]} JavaScript code that concatenates all imported CSS
197
+ * @returns {string[]} JS expressions, one per `@import` dependency
91
198
  */
92
- _generateImportCode(module, generateContext, getDefaultExport = true) {
93
- const moduleGraph = generateContext.moduleGraph;
94
- /** @type {{ expr: string, type: CssParserExportType }[]} */
199
+ _generateImportSideEffects(module, generateContext) {
200
+ const { moduleGraph, concatenationScope } = generateContext;
95
201
  const parts = [];
96
202
 
97
- // Iterate through module.dependencies to maintain source order
98
203
  for (const dep of module.dependencies) {
99
- if (dep instanceof CssImportDependency) {
100
- /** @type {CssModule} */
101
- const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
102
- const importVar = generateContext.runtimeTemplate.moduleExports({
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({
103
214
  module: depModule,
104
215
  chunkGraph: generateContext.chunkGraph,
105
- request: /** @type {CssModule} */ (depModule).userRequest,
216
+ request: depModule.userRequest,
106
217
  weak: false,
107
218
  runtimeRequirements: generateContext.runtimeRequirements
108
- });
219
+ })
220
+ );
221
+ }
109
222
 
110
- if (getDefaultExport) {
111
- generateContext.runtimeRequirements.add(
112
- RuntimeGlobals.compatGetDefaultExport
113
- );
114
- parts.push({
115
- expr: `(${RuntimeGlobals.compatGetDefaultExport}(${importVar})() || "")`,
116
- type: /** @type {CssParserExportType} */ (
117
- /** @type {CssModule} */ (depModule).exportType
118
- )
119
- });
120
- } else {
121
- parts.push({
122
- expr: importVar,
123
- type: /** @type {CssParserExportType} */ (
124
- /** @type {CssModule} */ (depModule).exportType
125
- )
126
- });
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;
127
263
  }
264
+ const depMerged = this._generateMergedContentSource(
265
+ depModule,
266
+ generateContext,
267
+ ancestors
268
+ );
269
+ if (depMerged) parts.push(depMerged);
128
270
  }
129
- }
130
271
 
131
- return parts;
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
+ }
132
281
  }
133
282
 
134
283
  /**
@@ -171,23 +320,32 @@ class CssGenerator extends Generator {
171
320
  }
172
321
 
173
322
  /**
174
- * Convert a CSS Source to a JS string literal Source, preserving source map.
175
- * Wraps the CSS content with JSON.stringify so it can be embedded in JS code.
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.
176
326
  * @param {Source} cssSource the CSS source
177
- * @param {NormalModule} module the module
327
+ * @param {import("../../declarations/WebpackOptions").DevTool | undefined} devtool the devtool option
178
328
  * @returns {Source} a Source representing a JS string literal
179
329
  */
180
- _cssSourceToJsStringLiteral(cssSource, module) {
330
+ _cssToJsLiteral(cssSource, devtool) {
181
331
  const { source, map } = cssSource.sourceAndMap();
182
- const content = /** @type {string} */ (source);
183
- const escaped = JSON.stringify(content);
332
+ let content = /** @type {string} */ (source);
184
333
  if (map) {
185
- return new SourceMapSource(escaped, module.identifier(), map, content);
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}*/`;
186
343
  }
187
- return new RawSource(escaped);
344
+ return new RawSource(JSON.stringify(content));
188
345
  }
189
346
 
190
347
  /**
348
+ * Processes the provided module.
191
349
  * @param {NormalModule} module the current module
192
350
  * @param {Dependency} dependency the dependency to generate
193
351
  * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
@@ -245,6 +403,7 @@ class CssGenerator extends Generator {
245
403
  }
246
404
 
247
405
  /**
406
+ * Processes the provided module.
248
407
  * @param {NormalModule} module the module to generate
249
408
  * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
250
409
  * @param {ReplaceSource} source the current replace source which can be modified
@@ -276,6 +435,7 @@ class CssGenerator extends Generator {
276
435
  }
277
436
 
278
437
  /**
438
+ * Generates generated code for this runtime module.
279
439
  * @param {NormalModule} module module for which the code should be generated
280
440
  * @param {GenerateContext} generateContext context for generate
281
441
  * @returns {Source | null} generated code
@@ -291,7 +451,8 @@ class CssGenerator extends Generator {
291
451
  /** @type {CssData} */
292
452
  const cssData = {
293
453
  esModule: /** @type {boolean} */ (this._esModule),
294
- exports: new Map()
454
+ exports: new Map(),
455
+ exportLocs: new Map()
295
456
  };
296
457
 
297
458
  this.sourceModule(module, initFragments, source, {
@@ -301,6 +462,11 @@ class CssGenerator extends Generator {
301
462
 
302
463
  switch (generateContext.type) {
303
464
  case JAVASCRIPT_TYPE: {
465
+ const compilation = generateContext.runtimeTemplate.compilation;
466
+ const devtool = compilation.options.devtool;
467
+ const isCssModule = /** @type {BuildMeta} */ (module.buildMeta)
468
+ .isCssModule;
469
+
304
470
  const generateContentCode = () => {
305
471
  switch (exportType) {
306
472
  case "style": {
@@ -309,15 +475,24 @@ class CssGenerator extends Generator {
309
475
  generateContext
310
476
  );
311
477
  if (!cssSource) return "";
312
- const moduleId = generateContext.chunkGraph.getModuleId(module);
313
478
 
314
479
  generateContext.runtimeRequirements.add(
315
480
  RuntimeGlobals.cssInjectStyle
316
481
  );
317
482
 
483
+ const moduleId = generateContext.chunkGraph.getModuleId(module);
484
+
485
+ if (generateContext.concatenationScope) {
486
+ return new ConcatSource(
487
+ `__webpack_css_styles__.push([${JSON.stringify(moduleId)}, `,
488
+ this._cssToJsLiteral(cssSource, devtool),
489
+ "]);"
490
+ );
491
+ }
492
+
318
493
  return new ConcatSource(
319
- `${RuntimeGlobals.cssInjectStyle}(${JSON.stringify(moduleId || "")}, `,
320
- this._cssSourceToJsStringLiteral(cssSource, module),
494
+ `${RuntimeGlobals.cssInjectStyle}(${JSON.stringify(moduleId)}, `,
495
+ this._cssToJsLiteral(cssSource, devtool),
321
496
  ");"
322
497
  );
323
498
  }
@@ -329,8 +504,8 @@ class CssGenerator extends Generator {
329
504
  const generateImportCode = () => {
330
505
  switch (exportType) {
331
506
  case "style": {
332
- return this._generateImportCode(module, generateContext, false)
333
- .map((part) => `${part.expr};`)
507
+ return this._generateImportSideEffects(module, generateContext)
508
+ .map((expr) => `${expr};`)
334
509
  .join("\n");
335
510
  }
336
511
  default:
@@ -340,44 +515,31 @@ class CssGenerator extends Generator {
340
515
  const generateExportCode = () => {
341
516
  /** @returns {Source} generated CSS text as JS expression */
342
517
  const generateCssText = () => {
343
- const importCode = this._generateImportCode(
344
- module,
345
- generateContext
346
- );
347
- const cssSource = this._generateContentSource(
518
+ const cssSource = this._generateMergedContentSource(
348
519
  module,
349
- generateContext
520
+ generateContext,
521
+ new Set()
350
522
  );
351
- const jsLiteral = cssSource
352
- ? this._cssSourceToJsStringLiteral(cssSource, module)
353
- : new RawSource('""');
354
523
 
355
- if (importCode.length > 0) {
356
- if (
357
- exportType === "css-style-sheet" ||
358
- importCode.some((part) => part.type !== exportType)
359
- ) {
360
- generateContext.runtimeRequirements.add(
361
- RuntimeGlobals.cssMergeStyleSheets
362
- );
524
+ let jsLiteral = cssSource
525
+ ? this._cssToJsLiteral(cssSource, devtool)
526
+ : new RawSource('""');
363
527
 
364
- const args = importCode.map((part) => part.expr);
365
- return new ConcatSource(
366
- `${RuntimeGlobals.cssMergeStyleSheets}([${args.join(", ")}, `,
367
- jsLiteral,
368
- "])"
369
- );
370
- }
371
- return new ConcatSource(
372
- `${generateContext.runtimeTemplate.concatenation(
373
- ...importCode
374
- )} + `,
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' + `,
375
535
  jsLiteral
376
536
  );
377
537
  }
538
+
378
539
  return jsLiteral;
379
540
  };
380
541
  /**
542
+ * Generates js default export.
381
543
  * @returns {Source | null} the default export
382
544
  */
383
545
  const generateJSDefaultExport = () => {
@@ -386,21 +548,19 @@ class CssGenerator extends Generator {
386
548
  return generateCssText();
387
549
  }
388
550
  case "css-style-sheet": {
389
- const constOrVar =
390
- generateContext.runtimeTemplate.renderConst();
391
- const cssText = generateCssText();
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.
392
554
  const fnPrefix =
393
555
  generateContext.runtimeTemplate.supportsArrowFunction()
394
556
  ? "() => {\n"
395
557
  : "function() {\n";
396
- const body =
397
- `${constOrVar} sheet = new CSSStyleSheet();\n` +
398
- "sheet.replaceSync(cssText);\n" +
399
- "return sheet;\n";
558
+ const constOrVar =
559
+ generateContext.runtimeTemplate.renderConst();
400
560
  return new ConcatSource(
401
- `(${fnPrefix}${constOrVar} cssText = `,
402
- cssText,
403
- `;\n${body}})()`
561
+ `(${fnPrefix}${constOrVar} sheet = new CSSStyleSheet();\nsheet.replaceSync(`,
562
+ generateCssText(),
563
+ ");\nreturn sheet;\n})()"
404
564
  );
405
565
  }
406
566
  default:
@@ -408,8 +568,6 @@ class CssGenerator extends Generator {
408
568
  }
409
569
  };
410
570
 
411
- const isCSSModule = /** @type {BuildMeta} */ (module.buildMeta)
412
- .isCSSModule;
413
571
  /** @type {Source | null} */
414
572
  const defaultExport = generateJSDefaultExport();
415
573
 
@@ -421,7 +579,7 @@ class CssGenerator extends Generator {
421
579
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
422
580
  }
423
581
 
424
- if (!defaultExport && cssData.exports.size === 0 && !isCSSModule) {
582
+ if (!defaultExport && cssData.exports.size === 0 && !isCssModule) {
425
583
  return new RawSource("");
426
584
  }
427
585
 
@@ -498,7 +656,7 @@ class CssGenerator extends Generator {
498
656
  // Should be after `concatenationScope` to allow module inlining
499
657
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
500
658
 
501
- if (!isCSSModule && !needNsObj) {
659
+ if (!isCssModule && !needNsObj) {
502
660
  return new ConcatSource(
503
661
  `${module.moduleArgument}.exports = `,
504
662
  /** @type {Source} */ (defaultExport)
@@ -546,26 +704,85 @@ class CssGenerator extends Generator {
546
704
  source.add("\n");
547
705
  }
548
706
  }
549
- return source;
550
- }
551
- case CSS_TYPE: {
707
+ // For link-type modules without any JS emit, skip source wrapping
552
708
  if (
553
- !(
554
- this._exportsOnly ||
555
- /** @type {boolean} */ (exportType && exportType !== "link")
556
- )
709
+ exportType === "link" &&
710
+ !isCssModule &&
711
+ cssData.exports.size === 0
712
+ ) {
713
+ return source;
714
+ }
715
+
716
+ const generatedJs = /** @type {string} */ (source.source());
717
+ const sourceName = module.readableIdentifier(
718
+ compilation.requestShortener
719
+ );
720
+
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
+ if (
725
+ /** @type {ExportLocsMap} */
726
+ (cssData.exportLocs).size > 0
557
727
  ) {
728
+ const cssOriginal = module.originalSource();
729
+ if (cssOriginal) {
730
+ const sourceMap = buildExportsSourceMap(
731
+ generatedJs,
732
+ /** @type {ExportLocsMap} */
733
+ (cssData.exportLocs),
734
+ /** @type {string} */ (cssOriginal.source()),
735
+ sourceName
736
+ );
737
+ return new SourceMapSource(generatedJs, sourceName, sourceMap);
738
+ }
739
+ }
740
+ return new OriginalSource(generatedJs, sourceName);
741
+ }
742
+ case CSS_TYPE: {
743
+ if (!(this._exportsOnly || (exportType && exportType !== "link"))) {
558
744
  generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
559
745
  }
560
746
 
561
747
  return InitFragment.addToSource(source, initFragments, generateContext);
562
748
  }
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
+ }
563
779
  default:
564
780
  return null;
565
781
  }
566
782
  }
567
783
 
568
784
  /**
785
+ * Generates fallback output for the provided error condition.
569
786
  * @param {Error} error the error
570
787
  * @param {NormalModule} module module for which the code should be generated
571
788
  * @param {GenerateContext} generateContext context for generate
@@ -587,6 +804,7 @@ class CssGenerator extends Generator {
587
804
  }
588
805
 
589
806
  /**
807
+ * Returns the source types available for this module.
590
808
  * @param {NormalModule} module fresh module
591
809
  * @returns {SourceTypes} available types (do not mutate)
592
810
  */
@@ -613,6 +831,19 @@ class CssGenerator extends Generator {
613
831
  continue;
614
832
  }
615
833
 
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.
839
+ if (
840
+ connection.dependency &&
841
+ connection.dependency.category === "html-style"
842
+ ) {
843
+ sourceTypes.add(CSS_TEXT_TYPE);
844
+ continue;
845
+ }
846
+
616
847
  if (!connection.originModule) {
617
848
  continue;
618
849
  }
@@ -636,9 +867,11 @@ class CssGenerator extends Generator {
636
867
  this._exportsOnly ||
637
868
  /** @type {boolean} */ (exportType && exportType !== "link")
638
869
  ) {
639
- if (sourceTypes.has(JAVASCRIPT_TYPE)) {
640
- return JAVASCRIPT_TYPES;
641
- }
870
+ const hasJs = sourceTypes.has(JAVASCRIPT_TYPE);
871
+ const hasCssText = sourceTypes.has(CSS_TEXT_TYPE);
872
+ if (hasJs && hasCssText) return JAVASCRIPT_AND_CSS_TEXT_TYPES;
873
+ if (hasJs) return JAVASCRIPT_TYPES;
874
+ if (hasCssText) return CSS_TEXT_TYPES;
642
875
  return new Set();
643
876
  }
644
877
  if (sourceTypes.has(JAVASCRIPT_TYPE)) {
@@ -648,6 +881,7 @@ class CssGenerator extends Generator {
648
881
  }
649
882
 
650
883
  /**
884
+ * Returns the estimated size for the requested source type.
651
885
  * @param {NormalModule} module the module
652
886
  * @param {SourceType=} type source type
653
887
  * @returns {number} estimate size of the module
@@ -660,7 +894,7 @@ class CssGenerator extends Generator {
660
894
  return 42;
661
895
  }
662
896
  if (cssData.exports.size === 0) {
663
- if (/** @type {BuildMeta} */ (module.buildMeta).isCSSModule) {
897
+ if (/** @type {BuildMeta} */ (module.buildMeta).isCssModule) {
664
898
  return 42;
665
899
  }
666
900
  return 0;
@@ -690,11 +924,13 @@ class CssGenerator extends Generator {
690
924
  }
691
925
 
692
926
  /**
927
+ * Updates the hash with the data contributed by this instance.
693
928
  * @param {Hash} hash hash that will be modified
694
929
  * @param {UpdateHashContext} updateHashContext context for updating hash
695
930
  */
696
931
  updateHash(hash, { module }) {
697
932
  hash.update(/** @type {boolean} */ (this._esModule).toString());
933
+ hash.update(/** @type {boolean} */ (this._exportsOnly).toString());
698
934
  }
699
935
  }
700
936