webpack 5.107.1 → 5.108.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/hot/dev-server.js +2 -0
  2. package/lib/APIPlugin.js +8 -4
  3. package/lib/CacheFacade.js +7 -0
  4. package/lib/Chunk.js +4 -0
  5. package/lib/ChunkGraph.js +30 -9
  6. package/lib/CircularModulesPlugin.js +190 -0
  7. package/lib/CleanPlugin.js +2 -1
  8. package/lib/Compilation.js +396 -65
  9. package/lib/Compiler.js +52 -14
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextModuleFactory.js +45 -38
  14. package/lib/ContextReplacementPlugin.js +4 -0
  15. package/lib/DefinePlugin.js +89 -15
  16. package/lib/Dependency.js +111 -7
  17. package/lib/EntryOptionPlugin.js +39 -2
  18. package/lib/EntryPlugin.js +2 -0
  19. package/lib/ExportsInfo.js +314 -73
  20. package/lib/ExternalModule.js +82 -34
  21. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  22. package/lib/ExternalsPlugin.js +1 -0
  23. package/lib/FileSystemInfo.js +173 -23
  24. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  25. package/lib/FlagDependencyExportsPlugin.js +23 -0
  26. package/lib/FlagDependencyUsagePlugin.js +87 -5
  27. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  28. package/lib/Generator.js +8 -0
  29. package/lib/HotModuleReplacementPlugin.js +65 -28
  30. package/lib/IgnorePlugin.js +1 -0
  31. package/lib/InitFragment.js +5 -0
  32. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  33. package/lib/LazyBarrel.js +361 -0
  34. package/lib/LoaderTargetPlugin.js +1 -0
  35. package/lib/Module.js +21 -42
  36. package/lib/ModuleGraph.js +3 -2
  37. package/lib/ModuleProfile.js +27 -1
  38. package/lib/ModuleTemplate.js +2 -0
  39. package/lib/MultiCompiler.js +16 -0
  40. package/lib/MultiStats.js +1 -0
  41. package/lib/MultiWatching.js +2 -0
  42. package/lib/NodeStuffPlugin.js +22 -17
  43. package/lib/NormalModule.js +557 -77
  44. package/lib/NormalModuleReplacementPlugin.js +2 -0
  45. package/lib/PrefetchPlugin.js +2 -0
  46. package/lib/ProgressPlugin.js +9 -1
  47. package/lib/ProvidePlugin.js +1 -0
  48. package/lib/RawModule.js +20 -16
  49. package/lib/RecordIdsPlugin.js +1 -0
  50. package/lib/RuntimeGlobals.js +5 -0
  51. package/lib/RuntimePlugin.js +58 -26
  52. package/lib/RuntimeTemplate.js +278 -21
  53. package/lib/SelfModuleFactory.js +1 -0
  54. package/lib/SourceMapDevToolPlugin.js +105 -30
  55. package/lib/Stats.js +1 -0
  56. package/lib/Template.js +8 -2
  57. package/lib/TemplatedPathPlugin.js +473 -131
  58. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  59. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  60. package/lib/WarnNoModeSetPlugin.js +1 -0
  61. package/lib/WatchIgnorePlugin.js +1 -0
  62. package/lib/Watching.js +9 -0
  63. package/lib/WebpackOptionsApply.js +50 -5
  64. package/lib/asset/AssetBytesGenerator.js +11 -3
  65. package/lib/asset/AssetGenerator.js +47 -22
  66. package/lib/asset/AssetModule.js +47 -0
  67. package/lib/asset/AssetModulesPlugin.js +14 -14
  68. package/lib/asset/AssetParser.js +2 -2
  69. package/lib/asset/AssetSourceGenerator.js +8 -0
  70. package/lib/asset/RawDataUrlModule.js +12 -13
  71. package/lib/buildChunkGraph.js +88 -9
  72. package/lib/bun/BunTargetPlugin.js +48 -0
  73. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  74. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  75. package/lib/cache/IdleFileCachePlugin.js +4 -0
  76. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  77. package/lib/cache/PackFileCacheStrategy.js +1 -0
  78. package/lib/cache/ResolverCachePlugin.js +2 -0
  79. package/lib/cache/getLazyHashedEtag.js +9 -2
  80. package/lib/cache/mergeEtags.js +2 -0
  81. package/lib/cli.js +109 -19
  82. package/lib/config/browserslistTargetHandler.js +99 -0
  83. package/lib/config/defaults.js +147 -7
  84. package/lib/config/defineConfig.js +31 -0
  85. package/lib/config/normalization.js +5 -0
  86. package/lib/config/target.js +181 -2
  87. package/lib/container/ContainerEntryModule.js +15 -14
  88. package/lib/container/ContainerExposedDependency.js +2 -2
  89. package/lib/container/ContainerReferencePlugin.js +1 -1
  90. package/lib/container/FallbackDependency.js +5 -7
  91. package/lib/container/FallbackModule.js +10 -9
  92. package/lib/container/RemoteModule.js +20 -10
  93. package/lib/container/RemoteRuntimeModule.js +14 -12
  94. package/lib/css/CssGenerator.js +353 -327
  95. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  96. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  97. package/lib/css/CssModule.js +52 -23
  98. package/lib/css/CssModulesPlugin.js +107 -124
  99. package/lib/css/CssParser.js +2759 -2205
  100. package/lib/css/syntax.js +2859 -0
  101. package/lib/debug/ProfilingPlugin.js +2 -0
  102. package/lib/deno/DenoTargetPlugin.js +47 -0
  103. package/lib/dependencies/AMDDefineDependency.js +22 -17
  104. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  105. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  106. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  107. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  108. package/lib/dependencies/AMDRequireDependency.js +24 -20
  109. package/lib/dependencies/CachedConstDependency.js +3 -0
  110. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  111. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  112. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  113. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  114. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  115. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  116. package/lib/dependencies/CommonJsPlugin.js +1 -1
  117. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  118. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  120. package/lib/dependencies/ConstDependency.js +16 -11
  121. package/lib/dependencies/ContextDependency.js +4 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  123. package/lib/dependencies/ContextElementDependency.js +23 -14
  124. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  125. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  126. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  127. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  128. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  129. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  130. package/lib/dependencies/CssImportDependency.js +25 -1
  131. package/lib/dependencies/CssUrlDependency.js +23 -14
  132. package/lib/dependencies/DllEntryDependency.js +9 -13
  133. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  134. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  135. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  136. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  137. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  138. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  139. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  140. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  141. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  142. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  143. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  144. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  145. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  146. package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
  147. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  148. package/lib/dependencies/HarmonyExports.js +4 -1
  149. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  150. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  151. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  152. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  153. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  154. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  155. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  156. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
  157. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  158. package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
  159. package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
  160. package/lib/dependencies/HtmlSourceDependency.js +18 -0
  161. package/lib/dependencies/ImportContextDependency.js +5 -9
  162. package/lib/dependencies/ImportDependency.js +44 -2
  163. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  164. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  165. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  166. package/lib/dependencies/ImportParserPlugin.js +19 -0
  167. package/lib/dependencies/ImportWeakDependency.js +1 -0
  168. package/lib/dependencies/JsonExportsDependency.js +9 -9
  169. package/lib/dependencies/LoaderImportDependency.js +1 -0
  170. package/lib/dependencies/LocalModule.js +11 -12
  171. package/lib/dependencies/LocalModuleDependency.js +11 -13
  172. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  173. package/lib/dependencies/ModuleDependency.js +7 -0
  174. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  175. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  176. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  177. package/lib/dependencies/ProvidedDependency.js +31 -27
  178. package/lib/dependencies/PureExpressionDependency.js +7 -9
  179. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  180. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  181. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  182. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  183. package/lib/dependencies/RequireResolveDependency.js +1 -0
  184. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  185. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  186. package/lib/dependencies/StaticExportsDependency.js +10 -10
  187. package/lib/dependencies/SystemPlugin.js +2 -0
  188. package/lib/dependencies/URLContextDependency.js +5 -7
  189. package/lib/dependencies/URLDependency.js +14 -16
  190. package/lib/dependencies/UnsupportedDependency.js +8 -13
  191. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  192. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  193. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  194. package/lib/dependencies/WorkerDependency.js +19 -8
  195. package/lib/dependencies/WorkerPlugin.js +40 -10
  196. package/lib/dependencies/processExportInfo.js +13 -11
  197. package/lib/dll/DelegatedModule.js +29 -15
  198. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  199. package/lib/dll/DelegatedPlugin.js +1 -0
  200. package/lib/dll/DllEntryPlugin.js +3 -0
  201. package/lib/dll/DllModule.js +3 -2
  202. package/lib/dll/DllPlugin.js +16 -0
  203. package/lib/dll/DllReferencePlugin.js +3 -0
  204. package/lib/dll/LibManifestPlugin.js +1 -0
  205. package/lib/electron/ElectronTargetPlugin.js +22 -4
  206. package/lib/errors/ConcurrentCompilationError.js +1 -0
  207. package/lib/errors/HookWebpackError.js +11 -13
  208. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  209. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  210. package/lib/errors/JSONParseError.js +9 -8
  211. package/lib/errors/ModuleBuildError.js +16 -13
  212. package/lib/errors/ModuleDependencyError.js +8 -1
  213. package/lib/errors/ModuleDependencyWarning.js +8 -1
  214. package/lib/errors/ModuleError.js +5 -11
  215. package/lib/errors/ModuleHashingError.js +4 -0
  216. package/lib/errors/ModuleNotFoundError.js +3 -0
  217. package/lib/errors/ModuleParseError.js +5 -11
  218. package/lib/errors/ModuleRestoreError.js +2 -0
  219. package/lib/errors/ModuleStoreError.js +3 -0
  220. package/lib/errors/ModuleWarning.js +7 -11
  221. package/lib/errors/NodeStuffInWebError.js +1 -0
  222. package/lib/errors/NonErrorEmittedError.js +2 -0
  223. package/lib/errors/UnhandledSchemeError.js +1 -0
  224. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  225. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  226. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  227. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  228. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  229. package/lib/hmr/LazyCompilationPlugin.js +134 -6
  230. package/lib/html/HtmlGenerator.js +292 -50
  231. package/lib/html/HtmlModule.js +40 -0
  232. package/lib/html/HtmlModulesPlugin.js +287 -60
  233. package/lib/html/HtmlParser.js +1108 -1099
  234. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  235. package/lib/ids/IdHelpers.js +4 -2
  236. package/lib/index.js +19 -0
  237. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  238. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  239. package/lib/javascript/JavascriptGenerator.js +6 -2
  240. package/lib/javascript/JavascriptModule.js +54 -0
  241. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  242. package/lib/javascript/JavascriptParser.js +286 -159
  243. package/lib/json/JsonModule.js +40 -0
  244. package/lib/json/JsonModulesPlugin.js +7 -0
  245. package/lib/json/JsonParser.js +4 -2
  246. package/lib/library/AssignLibraryPlugin.js +5 -3
  247. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  248. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  249. package/lib/library/ModuleLibraryPlugin.js +54 -29
  250. package/lib/library/SystemLibraryPlugin.js +3 -3
  251. package/lib/node/NodeTargetPlugin.js +1 -0
  252. package/lib/node/NodeWatchFileSystem.js +38 -22
  253. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  254. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  255. package/lib/optimize/ConcatenatedModule.js +397 -78
  256. package/lib/optimize/ConstExportsPlugin.js +211 -0
  257. package/lib/optimize/InlineExports.js +178 -0
  258. package/lib/optimize/InnerGraph.js +372 -275
  259. package/lib/optimize/InnerGraphPlugin.js +196 -99
  260. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  261. package/lib/optimize/RealContentHashPlugin.js +14 -1
  262. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  263. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  264. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  265. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  266. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  267. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  268. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  269. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  270. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  271. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  272. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  273. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  274. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  275. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  276. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  277. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  278. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  279. package/lib/schemes/HttpUriPlugin.js +3 -2
  280. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  281. package/lib/serialization/ArraySerializer.js +4 -8
  282. package/lib/serialization/BinaryMiddleware.js +538 -468
  283. package/lib/serialization/DateObjectSerializer.js +2 -2
  284. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  285. package/lib/serialization/MapObjectSerializer.js +5 -9
  286. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  287. package/lib/serialization/ObjectMiddleware.js +50 -13
  288. package/lib/serialization/PlainObjectSerializer.js +9 -8
  289. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  290. package/lib/serialization/Serializer.js +1 -0
  291. package/lib/serialization/SetObjectSerializer.js +4 -8
  292. package/lib/sharing/ConsumeSharedModule.js +6 -7
  293. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  294. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  295. package/lib/sharing/ProvideSharedDependency.js +30 -15
  296. package/lib/sharing/ProvideSharedModule.js +30 -11
  297. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  298. package/lib/sharing/SharePlugin.js +3 -0
  299. package/lib/sharing/ShareRuntimeModule.js +18 -16
  300. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  301. package/lib/sharing/utils.js +1 -1
  302. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  303. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  304. package/lib/stats/StatsFactory.js +11 -9
  305. package/lib/stats/StatsPrinter.js +9 -2
  306. package/lib/url/URLParserPlugin.js +5 -2
  307. package/lib/util/AsyncQueue.js +10 -0
  308. package/lib/util/LazyBucketSortedSet.js +5 -0
  309. package/lib/util/LazySet.js +6 -4
  310. package/lib/util/LocConverter.js +11 -1
  311. package/lib/util/Semaphore.js +1 -0
  312. package/lib/util/SourceProcessor.js +106 -0
  313. package/lib/util/TupleSet.js +1 -0
  314. package/lib/util/WeakTupleMap.js +27 -1
  315. package/lib/util/chainedImports.js +3 -3
  316. package/lib/util/comparators.js +2 -2
  317. package/lib/util/concatenate.js +31 -7
  318. package/lib/util/createHash.js +0 -1
  319. package/lib/util/deterministicGrouping.js +19 -12
  320. package/lib/util/extractSourceMap.js +1 -1
  321. package/lib/util/findGraphRoots.js +2 -0
  322. package/lib/util/fs.js +16 -6
  323. package/lib/util/hash/DebugHash.js +1 -0
  324. package/lib/util/hash/hash-digest.js +24 -15
  325. package/lib/util/identifier.js +7 -0
  326. package/lib/util/internalSerializables.js +11 -2
  327. package/lib/util/magicComment.js +42 -0
  328. package/lib/util/makeSerializable.js +1 -0
  329. package/lib/util/nonNumericOnlyHash.js +30 -1
  330. package/lib/util/property.js +7 -1
  331. package/lib/util/publicPathPlaceholder.js +64 -0
  332. package/lib/util/registerExternalSerializer.js +4 -4
  333. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  334. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  335. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  336. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  337. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  338. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  339. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  340. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  341. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  342. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  343. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  344. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  345. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  346. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  347. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  348. package/package.json +36 -28
  349. package/schemas/WebpackOptions.check.js +1 -1
  350. package/schemas/WebpackOptions.json +212 -3
  351. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  352. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  353. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  354. package/schemas/plugins/HtmlParserOptions.json +3 -0
  355. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  356. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  357. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  358. package/types.d.ts +1592 -314
  359. package/lib/css/walkCssTokens.js +0 -2020
  360. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -379,6 +379,8 @@ class ContextModuleFactory extends ModuleFactory {
379
379
  if (!processedFiles || processedFiles.length === 0) {
380
380
  return callback(null, []);
381
381
  }
382
+ /** @type {ContextAlternativeRequest[]} */
383
+ const fileObjs = [];
382
384
  asyncLib.map(
383
385
  processedFiles.filter((p) => p.indexOf(".") !== 0),
384
386
  (segment, callback) => {
@@ -404,41 +406,16 @@ class ContextModuleFactory extends ModuleFactory {
404
406
  stat.isFile() &&
405
407
  (!include || include.test(subResource))
406
408
  ) {
407
- /** @type {{ context: string, request: string }} */
408
- const obj = {
409
+ // Collect for a single batched alternativeRequests call
410
+ // per directory below. Calling the hook once per file
411
+ // would pay per-call overhead (closure, resolverFactory
412
+ // lookup, array allocations) for every file in the
413
+ // context — which is the bulk of work on rebuilds.
414
+ fileObjs.push({
409
415
  context: ctx,
410
416
  request: `.${subResource.slice(ctx.length).replace(/\\/g, "/")}`
411
- };
412
-
413
- this.hooks.alternativeRequests.callAsync(
414
- [obj],
415
- options,
416
- (err, alternatives) => {
417
- if (err) return callback(err);
418
- callback(
419
- null,
420
- /** @type {ContextAlternativeRequest[]} */
421
- (alternatives)
422
- .filter((obj) =>
423
- regExp.test(/** @type {string} */ (obj.request))
424
- )
425
- .map((obj) => {
426
- const dep = new ContextElementDependency(
427
- `${obj.request}${resourceQuery}${resourceFragment}`,
428
- obj.request,
429
- typePrefix,
430
- /** @type {string} */
431
- (category),
432
- referencedExports,
433
- obj.context,
434
- attributes
435
- );
436
- dep.optional = true;
437
- return dep;
438
- })
439
- );
440
- }
441
- );
417
+ });
418
+ callback();
442
419
  } else {
443
420
  callback();
444
421
  }
@@ -450,16 +427,46 @@ class ContextModuleFactory extends ModuleFactory {
450
427
  (err, result) => {
451
428
  if (err) return callback(err);
452
429
 
453
- if (!result) return callback(null, []);
454
-
455
430
  /** @type {ContextElementDependency[]} */
456
431
  const flattenedResult = [];
457
432
 
458
- for (const item of result) {
459
- if (item) flattenedResult.push(...item);
433
+ if (result) {
434
+ for (const item of result) {
435
+ if (item) flattenedResult.push(...item);
436
+ }
460
437
  }
461
438
 
462
- callback(null, flattenedResult);
439
+ if (fileObjs.length === 0) {
440
+ return callback(null, flattenedResult);
441
+ }
442
+
443
+ this.hooks.alternativeRequests.callAsync(
444
+ fileObjs,
445
+ options,
446
+ (err, alternatives) => {
447
+ if (err) return callback(err);
448
+ for (const alt of /** @type {ContextAlternativeRequest[]} */ (
449
+ alternatives
450
+ )) {
451
+ if (!regExp.test(/** @type {string} */ (alt.request))) {
452
+ continue;
453
+ }
454
+ const dep = new ContextElementDependency(
455
+ `${alt.request}${resourceQuery}${resourceFragment}`,
456
+ alt.request,
457
+ typePrefix,
458
+ /** @type {string} */
459
+ (category),
460
+ referencedExports,
461
+ alt.context,
462
+ attributes
463
+ );
464
+ dep.optional = true;
465
+ flattenedResult.push(dep);
466
+ }
467
+ callback(null, flattenedResult);
468
+ }
469
+ );
463
470
  }
464
471
  );
465
472
  });
@@ -32,6 +32,7 @@ class ContextReplacementPlugin {
32
32
  newContentRecursive,
33
33
  newContentRegExp
34
34
  ) {
35
+ /** @type {RegExp} */
35
36
  this.resourceRegExp = resourceRegExp;
36
37
 
37
38
  // new webpack.ContextReplacementPlugin(/selector/, (context) => { /* Logic */ });
@@ -43,6 +44,7 @@ class ContextReplacementPlugin {
43
44
  typeof newContentResource === "string" &&
44
45
  typeof newContentRecursive === "object"
45
46
  ) {
47
+ /** @type {string | undefined} */
46
48
  this.newContentResource = newContentResource;
47
49
  /**
48
50
  * Stores new content create context map.
@@ -79,9 +81,11 @@ class ContextReplacementPlugin {
79
81
  this.newContentResource =
80
82
  /** @type {string | undefined} */
81
83
  (newContentResource);
84
+ /** @type {boolean | undefined} */
82
85
  this.newContentRecursive =
83
86
  /** @type {boolean | undefined} */
84
87
  (newContentRecursive);
88
+ /** @type {RegExp | undefined} */
85
89
  this.newContentRegExp =
86
90
  /** @type {RegExp | undefined} */
87
91
  (newContentRegExp);
@@ -31,9 +31,11 @@ const createHash = require("./util/createHash");
31
31
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
32
32
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
33
33
  /** @typedef {import("./javascript/JavascriptParser").DestructuringAssignmentProperties} DestructuringAssignmentProperties */
34
+ /** @typedef {import("./javascript/JavascriptParser").Members} Members */
34
35
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
35
36
  /** @typedef {import("./logging/Logger").Logger} Logger */
36
37
  /** @typedef {import("./Compilation")} Compilation */
38
+ /** @typedef {import("./NormalModule").NormalModuleBuildInfo} NormalModuleBuildInfo */
37
39
 
38
40
  /** @typedef {null | undefined | RegExp | EXPECTED_FUNCTION | string | number | boolean | bigint | undefined} CodeValuePrimitive */
39
41
  /** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive | RuntimeValue>} CodeValue */
@@ -140,6 +142,17 @@ function getObjKeys(properties) {
140
142
  return new Set([...properties].map((p) => p.id));
141
143
  }
142
144
 
145
+ /**
146
+ * Whether a value is a nested definition (plain object/array) to recurse into.
147
+ * @param {CodeValue} code code value
148
+ * @returns {code is Definitions} true for a plain object or array
149
+ */
150
+ const isObjectDefinition = (code) =>
151
+ Boolean(code) &&
152
+ typeof code === "object" &&
153
+ !(code instanceof RuntimeValue) &&
154
+ !(code instanceof RegExp);
155
+
143
156
  /** @typedef {Set<string> | null} ObjKeys */
144
157
  /** @typedef {boolean | undefined | null} AsiSafe */
145
158
 
@@ -439,7 +452,7 @@ class DefinePlugin {
439
452
  /** @type {ValueCacheVersion} */
440
453
  (compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
441
454
  parser.hooks.program.tap(PLUGIN_NAME, () => {
442
- const buildInfo = /** @type {BuildInfo} */ (
455
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (
443
456
  parser.state.module.buildInfo
444
457
  );
445
458
  if (!buildInfo.valueDependencies) {
@@ -454,9 +467,9 @@ class DefinePlugin {
454
467
  */
455
468
  const addValueDependency = (key) => {
456
469
  const buildInfo =
457
- /** @type {BuildInfo} */
470
+ /** @type {NormalModuleBuildInfo} */
458
471
  (parser.state.module.buildInfo);
459
- /** @type {NonNullable<BuildInfo["valueDependencies"]>} */
472
+ /** @type {NonNullable<NormalModuleBuildInfo["valueDependencies"]>} */
460
473
  (buildInfo.valueDependencies).set(
461
474
  VALUE_DEP_PREFIX + key,
462
475
  /** @type {ValueCacheVersion} */
@@ -487,12 +500,7 @@ class DefinePlugin {
487
500
  const walkDefinitions = (definitions, prefix) => {
488
501
  for (const key of Object.keys(definitions)) {
489
502
  const code = definitions[key];
490
- if (
491
- code &&
492
- typeof code === "object" &&
493
- !(code instanceof RuntimeValue) &&
494
- !(code instanceof RegExp)
495
- ) {
503
+ if (isObjectDefinition(code)) {
496
504
  walkDefinitions(
497
505
  /** @type {Definitions} */ (code),
498
506
  `${prefix + key}.`
@@ -774,6 +782,77 @@ class DefinePlugin {
774
782
  }
775
783
  return toConstantDependency(parser, strCode)(expr);
776
784
  });
785
+ // A property access not defined on the object resolves to `undefined`
786
+ // and the whole object is never inlined (issue #15559). Keyed by the
787
+ // chain root so dotted object keys (e.g. `a.b`) are also covered.
788
+ const chainParts = key.split(".");
789
+ // `import.meta` is one chain root (a MetaProperty), not two members.
790
+ const isMeta =
791
+ chainParts[0] === "import" && chainParts[1] === "meta";
792
+ const chainRoot = isMeta ? "import.meta" : chainParts[0];
793
+ const chainPrefix = chainParts.slice(isMeta ? 2 : 1);
794
+ /**
795
+ * Whether a member chain reads a property that is not defined.
796
+ * Collects every define key consulted so the caller can record a
797
+ * value dependency on each (a sibling key like `OBJECT.SUB2` affects
798
+ * the result even though `OBJECT` registered the handler).
799
+ * `member in value` keeps inherited members (e.g. `toString`) defined.
800
+ * @param {Members} members chain members (after the root)
801
+ * @param {string[]} deps consulted define keys (mutated)
802
+ * @returns {boolean} true when the access resolves to `undefined`
803
+ */
804
+ const isUndefinedMemberAccess = (members, deps) => {
805
+ if (members.length <= chainPrefix.length) return false;
806
+ for (let i = 0; i < chainPrefix.length; i++) {
807
+ if (members[i] !== chainPrefix[i]) return false;
808
+ }
809
+ /** @type {CodeValue} */
810
+ let value = /** @type {CodeValue} */ (obj);
811
+ let path = key;
812
+ for (let i = chainPrefix.length; i < members.length; i++) {
813
+ // a leaf with members left is a real property access on a value
814
+ if (!isObjectDefinition(value)) return false;
815
+ const member = members[i];
816
+ const nextPath = `${path}.${member}`;
817
+ if (member in value) {
818
+ value = value[member];
819
+ } else if (
820
+ Object.prototype.hasOwnProperty.call(definitions, nextPath)
821
+ ) {
822
+ // defined via a dotted sibling key, e.g. `OBJECT.SUB2`
823
+ deps.push(nextPath);
824
+ value = definitions[nextPath];
825
+ } else {
826
+ return true;
827
+ }
828
+ path = nextPath;
829
+ }
830
+ return false;
831
+ };
832
+ parser.hooks.expressionMemberChain
833
+ .for(chainRoot)
834
+ .tap(PLUGIN_NAME, (expr, members) => {
835
+ const deps = [key];
836
+ if (!isUndefinedMemberAccess(members, deps)) return;
837
+ for (const dep of deps) addValueDependency(dep);
838
+ return toConstantDependency(parser, "undefined")(expr);
839
+ });
840
+ // In a call, replace only the callee so the call itself is kept:
841
+ // `x.MISSING()` stays a (throwing) call and `x.MISSING?.()`
842
+ // short-circuits, with the object never inlined.
843
+ parser.hooks.callMemberChain
844
+ .for(chainRoot)
845
+ .tap(PLUGIN_NAME, (expr, members) => {
846
+ const deps = [key];
847
+ if (!isUndefinedMemberAccess(members, deps)) return;
848
+ for (const dep of deps) addValueDependency(dep);
849
+ toConstantDependency(
850
+ parser,
851
+ "undefined"
852
+ )(/** @type {Expression} */ (expr.callee));
853
+ parser.walkExpressions(expr.arguments);
854
+ return true;
855
+ });
777
856
  parser.hooks.typeof
778
857
  .for(key)
779
858
  .tap(
@@ -821,12 +900,7 @@ class DefinePlugin {
821
900
  warning.hideStack = true;
822
901
  compilation.warnings.push(warning);
823
902
  }
824
- if (
825
- code &&
826
- typeof code === "object" &&
827
- !(code instanceof RuntimeValue) &&
828
- !(code instanceof RegExp)
829
- ) {
903
+ if (isObjectDefinition(code)) {
830
904
  walkDefinitionsForValues(
831
905
  /** @type {Definitions} */ (code),
832
906
  `${prefix + key}.`
package/lib/Dependency.js CHANGED
@@ -60,11 +60,13 @@ const memoize = require("./util/memoize");
60
60
  * @property {ExportInfoName} name the name of the export
61
61
  * @property {boolean=} canMangle can the export be renamed (defaults to true)
62
62
  * @property {boolean=} terminalBinding is the export a terminal binding that should be checked for export star conflicts
63
+ * @property {boolean=} isPure calling this export has no observable side effects
63
64
  * @property {(string | ExportSpec)[]=} exports nested exports
64
65
  * @property {ModuleGraphConnection=} from when reexported: from which module
65
66
  * @property {string[] | null=} export when reexported: from which export
66
67
  * @property {number=} priority when reexported: with which priority
67
68
  * @property {boolean=} hidden export is not visible, because another export blends over it
69
+ * @property {import("./optimize/InlineExports").InlinedValue=} inlined when set: the export binds to a small primitive constant eligible for inlining
68
70
  */
69
71
 
70
72
  /** @typedef {Set<string>} ExportsSpecExcludeExports */
@@ -79,6 +81,7 @@ const memoize = require("./util/memoize");
79
81
  * @property {number=} priority when reexported: with which priority
80
82
  * @property {boolean=} canMangle can the export be renamed (defaults to true)
81
83
  * @property {boolean=} terminalBinding are the exports terminal bindings that should be checked for export star conflicts
84
+ * @property {boolean=} isPure calling these exports has no observable side effects
82
85
  * @property {Module[]=} dependencies module on which the result depends on
83
86
  */
84
87
 
@@ -87,6 +90,7 @@ const memoize = require("./util/memoize");
87
90
  * @typedef {object} ReferencedExport
88
91
  * @property {string[]} name name of the referenced export
89
92
  * @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
93
+ * @property {boolean=} canInline when false, the referenced export can not be substituted with an inlined literal at this site, defaults to true
90
94
  */
91
95
 
92
96
  /** @typedef {string[][]} RawReferencedExports */
@@ -94,6 +98,20 @@ const memoize = require("./util/memoize");
94
98
 
95
99
  /** @typedef {(moduleGraphConnection: ModuleGraphConnection, runtime: RuntimeSpec) => ConnectionState} GetConditionFn */
96
100
 
101
+ /**
102
+ * Lazy barrel classification of a dependency within a side-effect-free module.
103
+ * `LAZY_UNTIL_LOCAL`: locally provided export name (`getLazyName`), requesting it requires no dependency.
104
+ * `LAZY_UNTIL_ID`: named re-export (`getLazyName`) deferred until the export name is requested.
105
+ * `LAZY_UNTIL_FALLBACK`: star re-export, deferred until an unknown name or all names are requested.
106
+ * `LAZY_UNTIL_REQUEST`: deferred together with other dependencies of the same request.
107
+ * @typedef {"local" | "id" | "*" | "@"} LazyUntil
108
+ */
109
+
110
+ const LAZY_UNTIL_LOCAL = /** @type {"local"} */ ("local");
111
+ const LAZY_UNTIL_ID = /** @type {"id"} */ ("id");
112
+ const LAZY_UNTIL_FALLBACK = /** @type {"*"} */ ("*");
113
+ const LAZY_UNTIL_REQUEST = /** @type {"@"} */ ("@");
114
+
97
115
  const TRANSITIVE = /** @type {symbol} */ (Symbol("transitive"));
98
116
 
99
117
  const getIgnoredModule = memoize(() => {
@@ -112,15 +130,16 @@ class Dependency {
112
130
  this._parentDependenciesBlock = undefined;
113
131
  /** @type {number} */
114
132
  this._parentDependenciesBlockIndex = -1;
115
- // TODO check if this can be moved into ModuleDependency
116
- /** @type {boolean} */
117
- this.weak = false;
118
- // TODO check if this can be moved into ModuleDependency
133
+ // stays on base: also set on ContextDependency, which is not a ModuleDependency
119
134
  /** @type {boolean | undefined} */
120
135
  this.optional = false;
136
+ /** @type {number} */
121
137
  this._locSL = 0;
138
+ /** @type {number} */
122
139
  this._locSC = 0;
140
+ /** @type {number} */
123
141
  this._locEL = 0;
142
+ /** @type {number} */
124
143
  this._locEC = 0;
125
144
  /** @type {undefined | number} */
126
145
  this._locI = undefined;
@@ -189,7 +208,10 @@ class Dependency {
189
208
  }
190
209
  this._locI = "index" in loc ? loc.index : undefined;
191
210
  this._locN = "name" in loc ? loc.name : undefined;
192
- this._loc = loc;
211
+ // Don't retain the passed object; `get loc` rebuilds it from the numbers
212
+ // above on demand, so dependencies whose loc is never read hold 4 numbers
213
+ // instead of a SourceLocation + two Position objects.
214
+ this._loc = undefined;
193
215
  }
194
216
 
195
217
  /**
@@ -209,6 +231,42 @@ class Dependency {
209
231
  this._loc = undefined;
210
232
  }
211
233
 
234
+ /**
235
+ * Updates loc from a source location plus an explicit index, without
236
+ * materializing the `loc` object (keeps `get loc` lazy). Replaces the
237
+ * `dep.loc = Object.create(loc); dep.loc.index = i` pattern, which both
238
+ * allocated a copy and stored the index outside the serialized fields.
239
+ * @param {DependencyLocation} loc source location (start/end/name read from it)
240
+ * @param {number} index dependency index within the statement
241
+ */
242
+ setLocWithIndex(loc, index) {
243
+ this.loc = loc;
244
+ this._locI = index;
245
+ }
246
+
247
+ /**
248
+ * Compares two dependencies by source location for sorting a module's
249
+ * `dependencies`, without materializing the `loc` objects (`get loc` caches
250
+ * its result, so comparing through it would retain a location object on every
251
+ * sorted dependency). These dependencies always carry a real source position,
252
+ * so only start (line, column) and the within-statement index are compared; a
253
+ * dependency without an index sorts after one that has an index at the same
254
+ * position.
255
+ * @param {Dependency} a first dependency
256
+ * @param {Dependency} b second dependency
257
+ * @returns {-1 | 0 | 1} compare result
258
+ */
259
+ static compareLocations(a, b) {
260
+ if (a._locSL !== b._locSL) return a._locSL < b._locSL ? -1 : 1;
261
+ if (a._locSC !== b._locSC) return a._locSC < b._locSC ? -1 : 1;
262
+ const ai = a._locI;
263
+ const bi = b._locI;
264
+ if (ai === bi) return 0;
265
+ if (ai === undefined) return 1;
266
+ if (bi === undefined) return -1;
267
+ return ai < bi ? -1 : 1;
268
+ }
269
+
212
270
  /**
213
271
  * Returns a request context.
214
272
  * @returns {string | undefined} a request context
@@ -233,6 +291,45 @@ class Dependency {
233
291
  return TRANSITIVE;
234
292
  }
235
293
 
294
+ /**
295
+ * Returns the export name this dependency requests from its target module (lazy barrel optimization).
296
+ * @returns {string | true | null} export name, true for all exports, null for none
297
+ */
298
+ getForwardId() {
299
+ // unknown dependency types conservatively request all exports
300
+ return true;
301
+ }
302
+
303
+ /**
304
+ * Returns how this dependency may be deferred when its parent module is side-effect-free (lazy barrel optimization).
305
+ * @returns {LazyUntil | null} lazy classification, null when it must be processed eagerly
306
+ */
307
+ getLazyUntil() {
308
+ return null;
309
+ }
310
+
311
+ /**
312
+ * Returns the export name for a `LAZY_UNTIL_LOCAL`/`LAZY_UNTIL_ID` classification (lazy barrel optimization).
313
+ * @returns {string | null} export name, null when not applicable
314
+ */
315
+ getLazyName() {
316
+ return null;
317
+ }
318
+
319
+ /**
320
+ * Whether the lazy barrel currently defers creating this dependency's target module (lazy barrel optimization).
321
+ * @returns {boolean} true while deferred, so it must not be processed or rendered
322
+ */
323
+ isLazy() {
324
+ return false;
325
+ }
326
+
327
+ /**
328
+ * Sets whether the lazy barrel defers creating this dependency's target module (lazy barrel optimization).
329
+ * @param {boolean} value true to defer, false to create it now
330
+ */
331
+ setLazy(value) {}
332
+
236
333
  /**
237
334
  * Returns the referenced module and export
238
335
  * @deprecated
@@ -338,7 +435,6 @@ class Dependency {
338
435
  * @param {ObjectSerializerContext} context context
339
436
  */
340
437
  serialize({ write }) {
341
- write(this.weak);
342
438
  write(this.optional);
343
439
  write(this._locSL);
344
440
  write(this._locSC);
@@ -353,7 +449,6 @@ class Dependency {
353
449
  * @param {ObjectDeserializerContext} context context
354
450
  */
355
451
  deserialize({ read }) {
356
- this.weak = read();
357
452
  this.optional = read();
358
453
  this._locSL = read();
359
454
  this._locSC = read();
@@ -368,6 +463,11 @@ class Dependency {
368
463
  Dependency.NO_EXPORTS_REFERENCED = [];
369
464
  /** @type {RawReferencedExports} */
370
465
  Dependency.EXPORTS_OBJECT_REFERENCED = [[]];
466
+ // Like EXPORTS_OBJECT_REFERENCED, but the reference can be rendered as a
467
+ // decoupled namespace object, so the module's exports stay mangleable.
468
+ // Same shape as EXPORTS_OBJECT_REFERENCED; only distinguished by identity.
469
+ /** @type {RawReferencedExports} */
470
+ Dependency.EXPORTS_OBJECT_REFERENCED_MANGLEABLE = [[]];
371
471
 
372
472
  // TODO remove in webpack 6
373
473
  Object.defineProperty(Dependency.prototype, "module", {
@@ -430,5 +530,9 @@ Object.defineProperty(Dependency.prototype, "disconnect", {
430
530
  });
431
531
 
432
532
  Dependency.TRANSITIVE = TRANSITIVE;
533
+ Dependency.LAZY_UNTIL_LOCAL = LAZY_UNTIL_LOCAL;
534
+ Dependency.LAZY_UNTIL_ID = LAZY_UNTIL_ID;
535
+ Dependency.LAZY_UNTIL_FALLBACK = LAZY_UNTIL_FALLBACK;
536
+ Dependency.LAZY_UNTIL_REQUEST = LAZY_UNTIL_REQUEST;
433
537
 
434
538
  module.exports = Dependency;
@@ -5,14 +5,39 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { SyncBailHook } = require("tapable");
9
+
8
10
  /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
9
11
  /** @typedef {import("../declarations/WebpackOptions").EntryNormalized} Entry */
10
12
  /** @typedef {import("./Compiler")} Compiler */
11
13
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
12
14
 
15
+ /**
16
+ * @typedef {object} EntryOptionPluginHooks
17
+ * @property {SyncBailHook<[string, string, EntryDescription], string | undefined>} entry transform an entry into a different request (e.g. wrap a non-HTML entry in a synthetic HTML module); return `undefined` to keep the default behavior
18
+ */
19
+
13
20
  const PLUGIN_NAME = "EntryOptionPlugin";
14
21
 
22
+ /** @type {WeakMap<Compiler, EntryOptionPluginHooks>} */
23
+ const hooksMap = new WeakMap();
24
+
15
25
  class EntryOptionPlugin {
26
+ /**
27
+ * @param {Compiler} compiler the compiler
28
+ * @returns {EntryOptionPluginHooks} the hooks
29
+ */
30
+ static getHooks(compiler) {
31
+ let hooks = hooksMap.get(compiler);
32
+ if (hooks === undefined) {
33
+ hooks = {
34
+ entry: new SyncBailHook(["context", "name", "entryDescription"])
35
+ };
36
+ hooksMap.set(compiler, hooks);
37
+ }
38
+ return hooks;
39
+ }
40
+
16
41
  /**
17
42
  * Applies the plugin by registering its hooks on the compiler.
18
43
  * @param {Compiler} compiler the compiler instance one is tapping into
@@ -50,8 +75,19 @@ class EntryOptionPlugin {
50
75
  const descImport =
51
76
  /** @type {Exclude<EntryDescription["import"], undefined>} */
52
77
  (desc.import);
53
- for (const entry of descImport) {
54
- new EntryPlugin(context, entry, options).apply(compiler);
78
+ // A plugin (e.g. HtmlModulesPlugin) may rewrite the entry into a
79
+ // single synthetic request; otherwise each import becomes an entry.
80
+ const request = EntryOptionPlugin.getHooks(compiler).entry.call(
81
+ context,
82
+ name,
83
+ desc
84
+ );
85
+ if (request !== undefined) {
86
+ new EntryPlugin(context, request, options).apply(compiler);
87
+ } else {
88
+ for (const entry of descImport) {
89
+ new EntryPlugin(context, entry, options).apply(compiler);
90
+ }
55
91
  }
56
92
  }
57
93
  }
@@ -77,6 +113,7 @@ class EntryOptionPlugin {
77
113
  chunkLoading: desc.chunkLoading,
78
114
  asyncChunks: desc.asyncChunks,
79
115
  wasmLoading: desc.wasmLoading,
116
+ worker: desc.worker,
80
117
  library: desc.library
81
118
  };
82
119
  if (desc.chunkLoading) {
@@ -20,7 +20,9 @@ class EntryPlugin {
20
20
  * @param {EntryOptions | string=} options entry options (passing a string is deprecated)
21
21
  */
22
22
  constructor(context, entry, options) {
23
+ /** @type {string} */
23
24
  this.context = context;
25
+ /** @type {string} */
24
26
  this.entry = entry;
25
27
  this.options = options || "";
26
28
  }