webpack 5.112.0 → 5.112.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/bin/webpack.js +13 -7
  2. package/lib/Compilation.js +152 -60
  3. package/lib/Compiler.js +12 -25
  4. package/lib/asset/AssetBytesGenerator.js +14 -6
  5. package/lib/asset/AssetBytesParser.js +10 -8
  6. package/lib/asset/AssetGenerator.js +36 -48
  7. package/lib/asset/AssetModule.js +11 -0
  8. package/lib/asset/AssetModulesPlugin.js +5 -4
  9. package/lib/asset/AssetParser.js +8 -8
  10. package/lib/asset/AssetSourceGenerator.js +16 -8
  11. package/lib/asset/AssetSourceParser.js +10 -8
  12. package/lib/asset/WebManifestGenerator.js +11 -6
  13. package/lib/asset/WebManifestParser.js +3 -3
  14. package/lib/async-modules/AsyncModuleHelpers.js +8 -2
  15. package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
  16. package/lib/cache/CacheFacade.js +1 -1
  17. package/lib/cache/PackFileCacheStrategy.js +6 -10
  18. package/lib/cache/ResolverCachePlugin.js +58 -8
  19. package/lib/config/WebpackOptionsApply.js +8 -28
  20. package/lib/config/cli.js +9 -6
  21. package/lib/config/defaults.js +24 -13
  22. package/lib/config/getClaimedAssetTypes.js +2 -2
  23. package/lib/config/target.js +1 -1
  24. package/lib/context/ContextModule.js +1 -1
  25. package/lib/context/ContextModuleFactory.js +1 -1
  26. package/lib/context/ContextReplacementPlugin.js +3 -9
  27. package/lib/css/CssGenerator.js +40 -37
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +2 -2
  30. package/lib/css/CssParser.js +33 -32
  31. package/lib/css/conventions.js +1 -1
  32. package/lib/css/data.js +224 -219
  33. package/lib/css/syntax-parser.js +1159 -298
  34. package/lib/css/syntax-printer.js +90 -35
  35. package/lib/debug/ProfilingPlugin.js +65 -43
  36. package/lib/define/DefinePlugin.js +10 -15
  37. package/lib/define/DotenvPlugin.js +10 -6
  38. package/lib/define/EnvironmentPlugin.js +4 -2
  39. package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
  40. package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  41. package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
  42. package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
  43. package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
  44. package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
  45. package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
  46. package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
  47. package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
  48. package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
  49. package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
  50. package/lib/dependencies/core/CachedConstDependency.js +9 -6
  51. package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
  52. package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
  53. package/lib/dependencies/css/CssUrlDependency.js +2 -6
  54. package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
  55. package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
  56. package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
  57. package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
  58. package/lib/dependencies/esm/ESMExports.js +2 -10
  59. package/lib/dependencies/esm/ESMImportDependency.js +17 -2
  60. package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
  61. package/lib/dependencies/esm/ESMImportGuard.js +11 -23
  62. package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
  63. package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
  64. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  65. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  66. package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
  67. package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
  68. package/lib/dependencies/helpers/DynamicExports.js +4 -6
  69. package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
  70. package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
  71. package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
  72. package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
  73. package/lib/dependencies/import/ImportParserPlugin.js +3 -6
  74. package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
  75. package/lib/dependencies/url/URLParserPlugin.js +1 -1
  76. package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
  77. package/lib/devtool/ModuleFilenameHelpers.js +1 -1
  78. package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
  79. package/lib/dll/DelegatedModule.js +3 -3
  80. package/lib/dll/DllModule.js +3 -1
  81. package/lib/dll/DllReferencePlugin.js +1 -4
  82. package/lib/errors/AbstractMethodError.js +1 -1
  83. package/lib/errors/ErrorHelpers.js +2 -1
  84. package/lib/errors/HookWebpackError.js +2 -1
  85. package/lib/errors/JSONParseError.js +4 -4
  86. package/lib/errors/WebpackError.js +3 -2
  87. package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
  88. package/lib/externals/ExternalModule.js +12 -9
  89. package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
  90. package/lib/externals/ExternalsPlugin.js +1 -1
  91. package/lib/fs/FileSystemInfo.js +4 -4
  92. package/lib/graph/AsyncDependenciesBlock.js +1 -1
  93. package/lib/graph/ChunkGraph.js +5 -0
  94. package/lib/graph/Dependency.js +8 -2
  95. package/lib/graph/ExportsInfo.js +1 -1
  96. package/lib/graph/ModuleGraph.js +14 -3
  97. package/lib/graph/buildChunkGraph.js +17 -19
  98. package/lib/graph/findGraphRoots.js +1 -1
  99. package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
  100. package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
  101. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
  102. package/lib/hmr/LazyCompilationPlugin.js +1 -7
  103. package/lib/html/HtmlGenerator.js +25 -17
  104. package/lib/html/HtmlModule.js +11 -1
  105. package/lib/html/HtmlModulesPlugin.js +12 -11
  106. package/lib/html/HtmlParser.js +10 -9
  107. package/lib/html/builtinEmbeddedRenderer.js +31 -33
  108. package/lib/html/data.js +42 -21
  109. package/lib/html/htmlMinify.js +4 -1
  110. package/lib/html/syntax-parser.js +34 -35
  111. package/lib/html/syntax-printer.js +2 -3
  112. package/lib/html/xmlMinify.js +4 -1
  113. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  114. package/lib/index.js +13 -12
  115. package/lib/javascript/APIPlugin.js +7 -13
  116. package/lib/javascript/BasicEvaluatedExpression.js +5 -5
  117. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
  118. package/lib/javascript/ConstPlugin.js +1 -1
  119. package/lib/javascript/JavascriptGenerator.js +16 -11
  120. package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
  121. package/lib/javascript/JavascriptModule.js +10 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +2 -4
  123. package/lib/javascript/JavascriptParser.js +99 -11
  124. package/lib/javascript/ScopeAnalyzer.js +183 -107
  125. package/lib/javascript/UseStrictPlugin.js +2 -5
  126. package/lib/javascript/jsMinify.js +1 -1
  127. package/lib/javascript/regexp.js +2 -2
  128. package/lib/javascript/syntax-parser.js +2114 -1506
  129. package/lib/javascript/syntax-printer-data.js +167 -1
  130. package/lib/javascript/syntax-printer.js +9554 -2782
  131. package/lib/json/JsonGenerator.js +15 -7
  132. package/lib/json/JsonModule.js +11 -0
  133. package/lib/json/JsonParser.js +7 -6
  134. package/lib/library/AssignLibraryPlugin.js +1 -1
  135. package/lib/library/JsonpLibraryPlugin.js +1 -1
  136. package/lib/library/ModuleLibraryPlugin.js +399 -23
  137. package/lib/loaders/LoaderRunner.js +76 -38
  138. package/lib/loaders/loadLoader.js +16 -10
  139. package/lib/module/Generator.js +17 -9
  140. package/lib/module/Module.js +2 -2
  141. package/lib/module/NormalModule.js +7 -5
  142. package/lib/module/NormalModuleFactory.js +11 -17
  143. package/lib/module/Parser.js +9 -2
  144. package/lib/module/extractSourceMap.js +69 -18
  145. package/lib/module/findCaseMismatch.js +2 -2
  146. package/lib/node/ExternalModuleInitFragment.js +2 -2
  147. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
  148. package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
  149. package/lib/node/nodeConsole.js +4 -3
  150. package/lib/optimize/CircularModulesPlugin.js +1 -1
  151. package/lib/optimize/ConcatenatedModule.js +2 -6
  152. package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
  153. package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
  154. package/lib/optimize/InlineExports.js +4 -7
  155. package/lib/optimize/LazyBarrels.js +41 -5
  156. package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
  157. package/lib/optimize/RealContentHashPlugin.js +2 -6
  158. package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
  159. package/lib/optimize/SplitChunksPlugin.js +11 -24
  160. package/lib/optimize/TupleQueue.js +1 -1
  161. package/lib/output/CleanPlugin.js +3 -1
  162. package/lib/output/CopyPlugin.js +3 -4
  163. package/lib/performance/EvalUsagePlugin.js +1 -3
  164. package/lib/performance/HotspotsPlugin.js +33 -9
  165. package/lib/performance/PureAnnotationsPlugin.js +16 -10
  166. package/lib/performance/TopLevelThisPlugin.js +17 -9
  167. package/lib/prefetch/ResourceHintPlugin.js +1 -1
  168. package/lib/provide/ProvidedDependency.js +36 -4
  169. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  170. package/lib/rules/RuleSetCompiler.js +15 -5
  171. package/lib/rules/UseEffectRulePlugin.js +1 -3
  172. package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
  173. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
  174. package/lib/runtime/RuntimeGlobals.js +6 -0
  175. package/lib/runtime/RuntimePlugin.js +2 -0
  176. package/lib/schemes/HttpUriPlugin.js +1 -2
  177. package/lib/schemes/VirtualUrlPlugin.js +3 -1
  178. package/lib/serialization/AggregateErrorSerializer.js +3 -3
  179. package/lib/serialization/BinaryMiddleware.js +4 -1
  180. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  181. package/lib/serialization/ObjectMiddleware.js +17 -15
  182. package/lib/serialization/PlainObjectSerializer.js +3 -7
  183. package/lib/serialization/Serializer.js +21 -11
  184. package/lib/serialization/SerializerMiddleware.js +8 -6
  185. package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
  186. package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
  187. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
  188. package/lib/stats/StatsFactory.js +194 -24
  189. package/lib/stats/StatsPrinter.js +126 -13
  190. package/lib/template/DependencyTemplate.js +1 -1
  191. package/lib/template/RuntimeTemplate.js +13 -32
  192. package/lib/template/Template.js +1 -1
  193. package/lib/util/SourceProcessor.js +98 -15
  194. package/lib/util/WeakTupleMap.js +10 -4
  195. package/lib/util/cleverMerge.js +61 -33
  196. package/lib/util/comparators.js +9 -5
  197. package/lib/util/dataURL.js +2 -0
  198. package/lib/util/deprecation.js +4 -3
  199. package/lib/util/globUtils.js +1 -4
  200. package/lib/util/internalSerializables.js +2 -0
  201. package/lib/util/makeSerializable.js +6 -4
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/parseJson.js +2 -2
  204. package/lib/util/serialization.js +31 -27
  205. package/lib/wasm/AsyncWasmModule.js +12 -2
  206. package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
  207. package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
  208. package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
  209. package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
  210. package/lib/wasm-sync/SyncWasmModule.js +16 -1
  211. package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
  212. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
  213. package/lib/wasm-sync/WebAssemblyParser.js +10 -12
  214. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
  215. package/lib/web/FetchCompileWasmPlugin.js +2 -6
  216. package/package.json +16 -18
  217. package/schemas/WebpackOptions.check.js +3 -3
  218. package/schemas/WebpackOptions.json +2 -2
  219. package/schemas/plugins/BannerPlugin.check.js +3 -3
  220. package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
  221. package/schemas/plugins/HtmlParserOptions.check.js +3 -3
  222. package/schemas/plugins/IgnorePlugin.check.js +3 -3
  223. package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
  224. package/schemas/plugins/ManifestPlugin.check.js +3 -3
  225. package/schemas/plugins/ProgressPlugin.check.js +3 -3
  226. package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
  227. package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
  228. package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
  229. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
  230. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
  231. package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
  232. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
  233. package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
  234. package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
  235. package/schemas/plugins/container/ExternalsType.check.js +3 -3
  236. package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
  237. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
  238. package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
  239. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
  240. package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
  241. package/schemas/plugins/css/CssParserOptions.check.js +3 -3
  242. package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
  243. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  244. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  245. package/schemas/plugins/dll/DllPlugin.check.js +3 -3
  246. package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
  247. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
  248. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
  249. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
  250. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
  251. package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
  252. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
  253. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
  254. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
  255. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
  256. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  257. package/schemas/plugins/output/CleanOptions.json +3 -0
  258. package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
  259. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
  260. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
  261. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
  262. package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
  263. package/types.d.ts +1482 -358
@@ -127,6 +127,7 @@ const metaIsCsp = (attrs) => {
127
127
  return false;
128
128
  };
129
129
 
130
+ /** @import { BuiltHtmlModule, HtmlNormalModule } from "./HtmlModule" */
130
131
  /** @import { Source } from "webpack-sources" */
131
132
  /** @import { HtmlGeneratorOptions } from "../../declarations/WebpackOptions" */
132
133
  /** @typedef {import("../../declarations/WebpackOptions").OutputHtmlOptions["csp"]} CspOption */
@@ -162,7 +163,6 @@ const metaIsCsp = (attrs) => {
162
163
  */
163
164
  /** @import ModuleGraph from "../graph/ModuleGraph" */
164
165
  /** @import NormalModule from "../module/NormalModule" */
165
- /** @import { HtmlModuleBuildInfo } from "./HtmlModule" */
166
166
  /** @import RuntimeTemplate from "../template/RuntimeTemplate" */
167
167
  /** @import Hash from "../util/Hash" */
168
168
  /**
@@ -316,6 +316,14 @@ const rebaseCssUrls = (css, fromFile, toFile, outputPath) => {
316
316
  return last === 0 ? css : out + css.slice(last);
317
317
  };
318
318
 
319
+ /**
320
+ * The module type the JSDoc inherited from `Generator` names.
321
+ * @typedef {HtmlNormalModule} TModule
322
+ */
323
+
324
+ /**
325
+ * @extends {Generator<TModule>}
326
+ */
319
327
  class HtmlGenerator extends Generator {
320
328
  /**
321
329
  * Emit a sentinel for a chunk URL that can't be resolved at code-gen time
@@ -655,7 +663,7 @@ class HtmlGenerator extends Generator {
655
663
  ) {
656
664
  if (!content.includes("__WEBPACK_HTML_INLINE__")) return content;
657
665
  const chunksById = getChunksById(compilation);
658
- const outputPath = /** @type {string} */ (compilation.outputOptions.path);
666
+ const outputPath = compilation.outputOptions.path;
659
667
  return content.replace(
660
668
  INLINE_SENTINEL_STATEMENT_REGEXP,
661
669
  (_, hexId, contentHashType, terminator) => {
@@ -1121,7 +1129,7 @@ class HtmlGenerator extends Generator {
1121
1129
 
1122
1130
  /**
1123
1131
  * Returns the reason this module cannot be concatenated, when one exists.
1124
- * @param {NormalModule} module module for which the bailout reason should be determined
1132
+ * @param {TModule} module module for which the bailout reason should be determined
1125
1133
  * @param {ConcatenationBailoutReasonContext} context context
1126
1134
  * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
1127
1135
  */
@@ -1141,7 +1149,7 @@ class HtmlGenerator extends Generator {
1141
1149
  * `originModule` (the EntryDependency added by `compilation.addEntry`) —
1142
1150
  * this covers both HTML-as-entry-point and a linked `type: "html"` page
1143
1151
  * (added as its own entry by HtmlModulesPlugin).
1144
- * @param {NormalModule} module module
1152
+ * @param {TModule} module module
1145
1153
  * @returns {boolean} true when the module is an entry
1146
1154
  */
1147
1155
  _isEntryModule(module) {
@@ -1158,7 +1166,7 @@ class HtmlGenerator extends Generator {
1158
1166
  * when the option is left unspecified, extraction defaults to on for HTML
1159
1167
  * modules used as compilation entries — that's the HTML-as-entry-point case
1160
1168
  * and a linked `type: "html"` page (which is added as its own entry).
1161
- * @param {NormalModule} module module
1169
+ * @param {TModule} module module
1162
1170
  * @returns {boolean} true when the `.html` file should be emitted
1163
1171
  */
1164
1172
  _shouldExtract(module) {
@@ -1172,7 +1180,7 @@ class HtmlGenerator extends Generator {
1172
1180
  * Whether this module exposes the `html` source type. Like `_shouldExtract`,
1173
1181
  * but `"inline"` also exposes it — the processed HTML is read back into the
1174
1182
  * host attribute (e.g. `<iframe srcdoc>`) instead of emitted as a file.
1175
- * @param {NormalModule} module module
1183
+ * @param {TModule} module module
1176
1184
  * @returns {boolean} true when the `html` source type is available
1177
1185
  */
1178
1186
  _shouldExposeHtmlType(module) {
@@ -1182,7 +1190,7 @@ class HtmlGenerator extends Generator {
1182
1190
 
1183
1191
  /**
1184
1192
  * Returns the source types available for this module.
1185
- * @param {NormalModule} module fresh module
1193
+ * @param {TModule} module fresh module
1186
1194
  * @returns {SourceTypes} available types (do not mutate)
1187
1195
  */
1188
1196
  getTypes(module) {
@@ -1206,7 +1214,7 @@ class HtmlGenerator extends Generator {
1206
1214
 
1207
1215
  /**
1208
1216
  * Returns the estimated size for the requested source type.
1209
- * @param {NormalModule} module the module
1217
+ * @param {TModule} module the module
1210
1218
  * @param {SourceType=} type source type
1211
1219
  * @returns {number} estimate size of the module
1212
1220
  */
@@ -1257,7 +1265,7 @@ class HtmlGenerator extends Generator {
1257
1265
 
1258
1266
  /**
1259
1267
  * Processes the provided module.
1260
- * @param {NormalModule} module the module to generate
1268
+ * @param {TModule} module the module to generate
1261
1269
  * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
1262
1270
  * @param {ReplaceSource} source the current replace source which can be modified
1263
1271
  * @param {GenerateContext} generateContext the generateContext
@@ -1266,7 +1274,7 @@ class HtmlGenerator extends Generator {
1266
1274
  sourceModule(module, initFragments, source, generateContext) {
1267
1275
  // Only `dependency` varies across `template.apply` calls, so one context
1268
1276
  // (and one lazy `chunkInitFragments` getter) serves the whole module.
1269
- /** @type {InitFragment<GenerateContext>[] | undefined} */
1277
+ /** @type {InitFragment<import("../javascript/JavascriptModulesPlugin").ChunkRenderContext>[] | undefined} */
1270
1278
  let chunkInitFragments;
1271
1279
  /** @type {DependencyTemplateContext} */
1272
1280
  const templateContext = {
@@ -1321,7 +1329,7 @@ class HtmlGenerator extends Generator {
1321
1329
  * `undefined`, the placeholders are preserved so the caller (typically
1322
1330
  * `HtmlModulesPlugin#renderManifest`, which only knows the final
1323
1331
  * `.html` filename after code generation) can resolve them itself.
1324
- * @param {NormalModule} module the module to render
1332
+ * @param {TModule} module the module to render
1325
1333
  * @param {GenerateContext} generateContext the generate context
1326
1334
  * @param {string=} undoPath value to substitute for `[webpack/auto]` placeholders
1327
1335
  * @returns {string} the rewritten HTML
@@ -1353,14 +1361,14 @@ class HtmlGenerator extends Generator {
1353
1361
  if (!rawContent.includes(PUBLIC_PATH_AUTO)) return rawContent;
1354
1362
  // A relative `<base href>` prepends `../`s so the base can't misdirect
1355
1363
  // the rewritten URLs (see `HtmlParser`).
1356
- const basePrefix =
1357
- /** @type {HtmlModuleBuildInfo} */ (module.buildInfo).baseUrlPrefix || "";
1364
+ const { buildInfo } = /** @type {BuiltHtmlModule} */ (module);
1365
+ const basePrefix = buildInfo.baseUrlPrefix || "";
1358
1366
  return rawContent.split(PUBLIC_PATH_AUTO).join(basePrefix + undoPath);
1359
1367
  }
1360
1368
 
1361
1369
  /**
1362
1370
  * Generates generated code for this runtime module.
1363
- * @param {NormalModule} module module for which the code should be generated
1371
+ * @param {TModule} module module for which the code should be generated
1364
1372
  * @param {GenerateContext} generateContext context for generate
1365
1373
  * @returns {Source | null} generated code
1366
1374
  */
@@ -1457,7 +1465,7 @@ class HtmlGenerator extends Generator {
1457
1465
  * express — fine in a dev-server context because the regular
1458
1466
  * (non-hot-update) `page.html` chunk is re-emitted on every rebuild,
1459
1467
  * so the reloaded page picks up the new head.
1460
- * @param {NormalModule} module module
1468
+ * @param {TModule} module module
1461
1469
  * @param {string} html the rewritten HTML content (with placeholders resolved)
1462
1470
  * @param {boolean} extracting whether the HTML module is being extracted as a real `.html` file
1463
1471
  * @param {RuntimeTemplate} runtimeTemplate runtime template (drives `const`/arrow emission based on environment support)
@@ -1677,7 +1685,7 @@ class HtmlGenerator extends Generator {
1677
1685
  /**
1678
1686
  * Generates fallback output for the provided error condition.
1679
1687
  * @param {Error} error the error
1680
- * @param {NormalModule} module module for which the code should be generated
1688
+ * @param {TModule} module module for which the code should be generated
1681
1689
  * @param {GenerateContext} generateContext context for generate
1682
1690
  * @returns {Source | null} generated code
1683
1691
  */
@@ -1704,7 +1712,7 @@ class HtmlGenerator extends Generator {
1704
1712
  /**
1705
1713
  * Updates the hash with the data contributed by this instance.
1706
1714
  * @param {Hash} hash hash that will be modified
1707
- * @param {UpdateHashContext} updateHashContext context for updating hash
1715
+ * @param {UpdateHashContext<TModule>} updateHashContext context for updating hash
1708
1716
  */
1709
1717
  updateHash(hash, updateHashContext) {
1710
1718
  hash.update("html");
@@ -14,7 +14,7 @@ const makeSerializable = require("../util/makeSerializable");
14
14
  * } from "../module/NormalModule"
15
15
  */
16
16
  /** @import { HtmlEntryInfo } from "./HtmlModulesPlugin" */
17
- /** @import { ModuleKinds } from "../module/Module" */
17
+ /** @import { BuildMeta, ModuleKinds } from "../module/Module" */
18
18
 
19
19
  /**
20
20
  * Defines the build info properties specific to html modules.
@@ -25,6 +25,16 @@ const makeSerializable = require("../util/makeSerializable");
25
25
 
26
26
  /** @typedef {NormalModuleBuildInfo & KnownHtmlModuleBuildInfo} HtmlModuleBuildInfo */
27
27
 
28
+ /**
29
+ * An html module before or after its build, typed with its build info.
30
+ * @typedef {NormalModule & { buildInfo?: HtmlModuleBuildInfo }} HtmlNormalModule
31
+ */
32
+
33
+ /**
34
+ * A built html module, typed with its build info and build meta.
35
+ * @typedef {NormalModule & { buildInfo: HtmlModuleBuildInfo, buildMeta: BuildMeta }} BuiltHtmlModule
36
+ */
37
+
28
38
  /**
29
39
  * Module class for `html` modules. HTML-specific properties should live here instead of `NormalModule`.
30
40
  */
@@ -75,7 +75,7 @@ const getCssModulesPlugin = memoize(() => require("../css/CssModulesPlugin"));
75
75
  /** @import Compiler from "../Compiler" */
76
76
  /** @import Module from "../module/Module" */
77
77
  /** @typedef {import("../Compilation").EntryData} EntryData */
78
- /** @import { HtmlModuleBuildInfo } from "./HtmlModule" */
78
+ /** @import { BuiltHtmlModule, HtmlModuleBuildInfo } from "./HtmlModule" */
79
79
  /** @import HtmlParser from "./HtmlParser" */
80
80
  /** @typedef {{ request: string, entryName: string, index: number, type: "script" | "script-module" | "modulepreload" | "stylesheet" | "html" | "preload" | "prefetch", css?: boolean, chunkName?: string }} HtmlEntryInfo */
81
81
  /**
@@ -444,8 +444,8 @@ class HtmlModulesPlugin {
444
444
  hash.update(content);
445
445
  return digestNonNumericOnly(
446
446
  hash,
447
- /** @type {string} */ (outputOptions.hashDigest),
448
- /** @type {number} */ (outputOptions.hashDigestLength)
447
+ outputOptions.hashDigest,
448
+ outputOptions.hashDigestLength
449
449
  );
450
450
  }
451
451
 
@@ -1249,7 +1249,13 @@ class HtmlModulesPlugin {
1249
1249
  // render base stay in sync.
1250
1250
  const parser = /** @type {HtmlParser} */ (module.parser);
1251
1251
 
1252
- return [parser.applyTemplate(source, module), ...rest];
1252
+ return [
1253
+ parser.applyTemplate(
1254
+ source,
1255
+ /** @type {BuiltHtmlModule} */ (module)
1256
+ ),
1257
+ ...rest
1258
+ ];
1253
1259
  }
1254
1260
 
1255
1261
  return result;
@@ -1329,7 +1335,7 @@ class HtmlModulesPlugin {
1329
1335
  : toTemplateSourceFileName(
1330
1336
  makePathsRelative(
1331
1337
  compiler.context,
1332
- /** @type {string} */ (resource),
1338
+ resource,
1333
1339
  compiler.root
1334
1340
  ).replace(/^\.\//, ""),
1335
1341
  compilation
@@ -1434,12 +1440,7 @@ class HtmlModulesPlugin {
1434
1440
  /** @type {HtmlModuleBuildInfo} */ (normalModule.buildInfo)
1435
1441
  .baseUrlPrefix || "";
1436
1442
  const undoPath =
1437
- basePrefix +
1438
- getUndoPath(
1439
- filename,
1440
- /** @type {string} */ (outputOptions.path),
1441
- false
1442
- );
1443
+ basePrefix + getUndoPath(filename, outputOptions.path, false);
1443
1444
  // Resolve linked-page (`type: "html"`) sentinels to each page's
1444
1445
  // emitted filename before the undo path, so the href is relative to
1445
1446
  // this page.
@@ -59,13 +59,12 @@ const getCommentCompilationWarning = memoize(() =>
59
59
  require("../errors/CommentCompilationWarning")
60
60
  );
61
61
 
62
+ /** @import { BuiltHtmlModule, HtmlNormalModule } from "./HtmlModule" */
62
63
  /** @import { HtmlParserOptions } from "../../declarations/WebpackOptions" */
63
64
  /** @import { Range } from "../javascript/JavascriptParser" */
64
- /** @import Module, { BuildInfo, BuildMeta } from "../module/Module" */
65
+ /** @import Module from "../module/Module" */
65
66
  /** @import { FileSystemDependencies } from "../Compilation" */
66
- /** @import NormalModule from "../module/NormalModule" */
67
67
  /** @import { ParserState, PreparsedAst } from "../module/Parser" */
68
- /** @import { HtmlModuleBuildInfo } from "./HtmlModule" */
69
68
 
70
69
  /**
71
70
  * @typedef {object} HtmlTemplateContext
@@ -718,6 +717,9 @@ const CONTENT_SOURCES = dict({
718
717
  style: { type: "stylesheet-style", filter: styleContentFilter }
719
718
  });
720
719
 
720
+ /**
721
+ * @extends {Parser<BuiltHtmlModule>}
722
+ */
721
723
  class HtmlParser extends Parser {
722
724
  /**
723
725
  * Creates an instance of HtmlParser.
@@ -803,14 +805,14 @@ class HtmlParser extends Parser {
803
805
  * dependency offsets against it) and the generator (which renders from
804
806
  * `module.originalSource()`) stay in agreement.
805
807
  * @param {string | Buffer} source the original source
806
- * @param {NormalModule} module the html module
808
+ * @param {HtmlNormalModule} module the html module
807
809
  * @returns {string | Buffer} the transformed source
808
810
  */
809
811
  applyTemplate(source, module) {
810
812
  if (!this.template) return source;
811
813
  // `processResult` runs after `_doBuild` has initialized these
812
814
  // dependency sets, so they are always present here.
813
- const buildInfo = /** @type {BuildInfo} */ (module.buildInfo);
815
+ const { buildInfo } = /** @type {BuiltHtmlModule} */ (module);
814
816
  const fileDependencies = /** @type {FileSystemDependencies} */ (
815
817
  buildInfo.fileDependencies
816
818
  );
@@ -876,7 +878,7 @@ class HtmlParser extends Parser {
876
878
 
877
879
  const locConverter = new LocConverter(source);
878
880
 
879
- const module = state.module;
881
+ const module = /** @type {BuiltHtmlModule} */ (state.module);
880
882
  const compilation = state.compilation;
881
883
  const { hashFunction, module: outputModule } = compilation.outputOptions;
882
884
  const context = compilation.compiler.context;
@@ -2185,7 +2187,7 @@ class HtmlParser extends Parser {
2185
2187
  }
2186
2188
  }
2187
2189
 
2188
- const buildInfo = /** @type {HtmlModuleBuildInfo} */ (module.buildInfo);
2190
+ const buildInfo = module.buildInfo;
2189
2191
  buildInfo.strict = true;
2190
2192
  if (baseUrlPrefix !== undefined) buildInfo.baseUrlPrefix = baseUrlPrefix;
2191
2193
  // WHY: hand the collected entries to HtmlModulesPlugin, which creates the
@@ -2214,8 +2216,7 @@ class HtmlParser extends Parser {
2214
2216
  };
2215
2217
  }
2216
2218
 
2217
- const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
2218
- buildMeta.exportsType = "default";
2219
+ module.buildMeta.exportsType = "default";
2219
2220
 
2220
2221
  state.module.addDependency(new StaticExportsDependency(["default"], true));
2221
2222
 
@@ -5,9 +5,12 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { SourceProcessor: CssSourceProcessor } = require("../css/syntax");
8
9
  const { CSS_TYPE } = require("../module/ModuleSourceTypeConstants");
10
+ const { JSON_TYPE, SVG_TYPE } = require("../util/dataURL");
11
+ const { SourceProcessor: HtmlSourceProcessor } = require("./syntax");
9
12
 
10
- /** @import { CssProcessOptions } from "../css/syntax-parser" */
13
+ /** @import { CssPrintOptions, CssProcessOptions } from "../css/syntax-parser" */
11
14
  /** @import { EmbeddedSourceRenderer } from "./syntax-printer" */
12
15
 
13
16
  /**
@@ -21,15 +24,6 @@ const { CSS_TYPE } = require("../module/ModuleSourceTypeConstants");
21
24
  * @property {boolean=} svg minify an SVG `data:` URL as the `.svg` assets are, wherever that is shorter (default false)
22
25
  */
23
26
 
24
- // Both are loaded on first render rather than at module load: a document that
25
- // embeds no CSS and no JSON pays for neither.
26
- /** @type {typeof import("../css/syntax") | undefined} */
27
- let _cssSyntax;
28
- /** @type {typeof import("./syntax-parser") | undefined} */
29
- let _htmlParser;
30
- /** @type {typeof import("./syntax") | undefined} */
31
- let _htmlSyntax;
32
-
33
27
  /**
34
28
  * Strip the whitespace between a JSON body's tokens, every literal copied byte
35
29
  * for byte. Re-serializing would round numbers, drop a duplicate key and rewrite
@@ -78,21 +72,14 @@ const stripJsonWhitespace = (json) => {
78
72
  * @returns {EmbeddedSourceRenderer} the renderer
79
73
  */
80
74
  const builtinEmbeddedRenderer = (options = {}) => {
81
- const { BLOCK_CONTENTS, JSON_TYPE, SVG_TYPE } =
82
- _htmlParser || (_htmlParser = require("./syntax-parser"));
83
- const { svg, ...cssOptions } = options;
84
- const sheet = {
85
- mode: /** @type {"minify"} */ ("minify"),
86
- ...cssOptions,
87
- // A stylesheet's own `url(data:image/svg+xml,…)`, which `renderSvg` answers.
88
- renderEmbeddedSource: svg
89
- ? /** @type {EmbeddedSourceRenderer} */ (
90
- (source, info) =>
91
- info.type === SVG_TYPE ? renderSvg(source) : undefined
92
- )
93
- : undefined
94
- };
95
- const block = { ...sheet, as: BLOCK_CONTENTS };
75
+ const { svg } = options;
76
+ // Built on first CSS render, so reading `options` (a lazy `transforms`
77
+ // included) waits until the CSS minifier loads.
78
+ /** @typedef {CssPrintOptions & { mode: "minify", as?: CssProcessOptions["as"] }} SheetOptions */
79
+ /** @type {SheetOptions | undefined} */
80
+ let sheet;
81
+ /** @type {SheetOptions | undefined} */
82
+ let block;
96
83
  // A `style=""` repeats across a document far more often than it varies.
97
84
  /** @type {Map<string, string>} */
98
85
  const blocks = new Map();
@@ -104,18 +91,31 @@ const builtinEmbeddedRenderer = (options = {}) => {
104
91
  return svg && info.as === undefined ? renderSvg(source) : undefined;
105
92
  }
106
93
  if (info.type !== CSS_TYPE) return undefined;
107
- const isBlock = info.as === BLOCK_CONTENTS;
94
+ const isBlock = info.as === "block-contents";
108
95
  if (isBlock) {
109
96
  const memoized = blocks.get(source);
110
97
  if (memoized !== undefined) return memoized;
111
98
  }
112
- const { SourceProcessor } =
113
- _cssSyntax || (_cssSyntax = require("../css/syntax"));
114
99
  let code;
115
100
  try {
116
- code = new SourceProcessor().process(
101
+ if (sheet === undefined) {
102
+ const { svg: _svg, ...cssOptions } = options;
103
+ sheet = {
104
+ mode: /** @type {"minify"} */ ("minify"),
105
+ ...cssOptions,
106
+ // A stylesheet's own `url(data:image/svg+xml,…)`, which `renderSvg` answers.
107
+ renderEmbeddedSource: svg
108
+ ? /** @type {EmbeddedSourceRenderer} */ (
109
+ (source, info) =>
110
+ info.type === SVG_TYPE ? renderSvg(source) : undefined
111
+ )
112
+ : undefined
113
+ };
114
+ block = { ...sheet, as: "block-contents" };
115
+ }
116
+ code = new CssSourceProcessor().process(
117
117
  source,
118
- isBlock ? block : sheet
118
+ /** @type {SheetOptions} */ (isBlock ? block : sheet)
119
119
  ).code;
120
120
  } catch (_err) {
121
121
  // Text the minifier cannot read is left as written, by declining.
@@ -130,12 +130,10 @@ const builtinEmbeddedRenderer = (options = {}) => {
130
130
  * @returns {string | undefined} it minified, or undefined where that is no shorter or it is not XML
131
131
  */
132
132
  const renderSvg = (source) => {
133
- const { SourceProcessor } =
134
- _htmlSyntax || (_htmlSyntax = require("./syntax"));
135
133
  let code;
136
134
  try {
137
135
  // `'` around an attribute, since the URL usually sits in `"` quotes.
138
- code = new SourceProcessor().process(source, {
136
+ code = new HtmlSourceProcessor().process(source, {
139
137
  xml: true,
140
138
  mode: "minify",
141
139
  xmlQuote: "'",
package/lib/html/data.js CHANGED
@@ -1870,28 +1870,49 @@ const ENUMERATED_KEYWORDS = Object.assign(Object.create(null), {
1870
1870
  const INVALID_VALUE_DEFAULT_DIFFERS = new Set(["track kind"]);
1871
1871
 
1872
1872
  /**
1873
- * Elements `removeEmptyElements` never drops: with no children and no attributes each is still doing its job, so an empty one is not a leftover.
1873
+ * Elements `removeEmptyElements` may drop: with no children and no attributes each renders nothing and is read by nothing; every other element, a custom one included, is kept.
1874
1874
  * @type {Set<string>}
1875
1875
  */
1876
- const EMPTY_ELEMENT_KEPT = new Set([
1877
- "canvas",
1878
- "dialog",
1879
- "meter",
1880
- "output",
1881
- "progress",
1882
- "slot",
1883
- "template",
1884
- "textarea",
1885
- "caption",
1886
- "col",
1887
- "colgroup",
1888
- "table",
1889
- "tbody",
1890
- "td",
1891
- "tfoot",
1892
- "th",
1893
- "thead",
1894
- "tr"
1876
+ const EMPTY_ELEMENT_DROPPED = new Set([
1877
+ "a",
1878
+ "abbr",
1879
+ "address",
1880
+ "article",
1881
+ "aside",
1882
+ "b",
1883
+ "bdi",
1884
+ "bdo",
1885
+ "cite",
1886
+ "code",
1887
+ "data",
1888
+ "del",
1889
+ "dfn",
1890
+ "div",
1891
+ "em",
1892
+ "footer",
1893
+ "head",
1894
+ "header",
1895
+ "i",
1896
+ "ins",
1897
+ "kbd",
1898
+ "label",
1899
+ "main",
1900
+ "mark",
1901
+ "nav",
1902
+ "s",
1903
+ "samp",
1904
+ "script",
1905
+ "section",
1906
+ "small",
1907
+ "span",
1908
+ "strong",
1909
+ "style",
1910
+ "sub",
1911
+ "sup",
1912
+ "time",
1913
+ "title",
1914
+ "u",
1915
+ "var"
1895
1916
  ]);
1896
1917
 
1897
1918
  /**
@@ -1992,7 +2013,7 @@ module.exports.CLEAR_TABLE_BODY = CLEAR_TABLE_BODY;
1992
2013
  module.exports.CLEAR_TABLE_ROW = CLEAR_TABLE_ROW;
1993
2014
  module.exports.COMMA_LIST_ATTRIBUTES = COMMA_LIST_ATTRIBUTES;
1994
2015
  module.exports.DOM_TOKEN_LIST_ATTRIBUTES = DOM_TOKEN_LIST_ATTRIBUTES;
1995
- module.exports.EMPTY_ELEMENT_KEPT = EMPTY_ELEMENT_KEPT;
2016
+ module.exports.EMPTY_ELEMENT_DROPPED = EMPTY_ELEMENT_DROPPED;
1996
2017
  module.exports.EMPTY_METADATA_ELEMENTS = EMPTY_METADATA_ELEMENTS;
1997
2018
  module.exports.EMPTY_REMOVABLE_ATTRIBUTES = EMPTY_REMOVABLE_ATTRIBUTES;
1998
2019
  module.exports.ENUMERATED_ATTRIBUTE_NAMES = ENUMERATED_ATTRIBUTE_NAMES;
@@ -95,7 +95,10 @@ const htmlMinify = async (
95
95
  rewriteCustomProperties: css.rewriteCustomProperties,
96
96
  unusedSymbols: css.unusedSymbols,
97
97
  pseudoClasses: css.pseudoClasses,
98
- transforms: webpack.css.syntax.parser.pickTransforms(css),
98
+ // Picked on first CSS render, which loads the CSS parser anyway.
99
+ get transforms() {
100
+ return webpack.css.syntax.parser.pickTransforms(css);
101
+ },
99
102
  svg
100
103
  });
101
104
  // One set of options, handed to the document pass and to each conditional