webpack 5.106.2 → 5.107.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +2 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/BannerPlugin.js +3 -4
  4. package/lib/Cache.js +3 -6
  5. package/lib/Chunk.js +21 -25
  6. package/lib/ChunkGroup.js +57 -15
  7. package/lib/CompatibilityPlugin.js +8 -7
  8. package/lib/Compilation.js +67 -37
  9. package/lib/Compiler.js +4 -13
  10. package/lib/ContextModule.js +2 -2
  11. package/lib/DefinePlugin.js +2 -2
  12. package/lib/Dependency.js +22 -1
  13. package/lib/DependencyTemplate.js +2 -1
  14. package/lib/EnvironmentPlugin.js +1 -1
  15. package/lib/EvalSourceMapDevToolPlugin.js +8 -10
  16. package/lib/ExportsInfo.js +30 -34
  17. package/lib/ExternalModule.js +91 -26
  18. package/lib/ExternalModuleFactoryPlugin.js +7 -1
  19. package/lib/FileSystemInfo.js +187 -72
  20. package/lib/Generator.js +3 -3
  21. package/lib/HotModuleReplacementPlugin.js +26 -8
  22. package/lib/IgnorePlugin.js +2 -1
  23. package/lib/Module.js +20 -19
  24. package/lib/ModuleFactory.js +1 -1
  25. package/lib/ModuleNotFoundError.js +3 -84
  26. package/lib/ModuleSourceTypeConstants.js +51 -19
  27. package/lib/ModuleTypeConstants.js +12 -3
  28. package/lib/MultiCompiler.js +2 -2
  29. package/lib/NodeStuffPlugin.js +1 -1
  30. package/lib/NormalModule.js +119 -77
  31. package/lib/NormalModuleFactory.js +47 -27
  32. package/lib/Parser.js +1 -1
  33. package/lib/ProgressPlugin.js +129 -56
  34. package/lib/RuntimeGlobals.js +5 -5
  35. package/lib/RuntimeModule.js +9 -7
  36. package/lib/RuntimePlugin.js +12 -1
  37. package/lib/SourceMapDevToolPlugin.js +250 -49
  38. package/lib/Template.js +1 -1
  39. package/lib/TemplatedPathPlugin.js +22 -4
  40. package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
  41. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  42. package/lib/WarnNoModeSetPlugin.js +16 -1
  43. package/lib/Watching.js +2 -3
  44. package/lib/WebpackError.js +3 -77
  45. package/lib/WebpackIsIncludedPlugin.js +1 -1
  46. package/lib/WebpackOptionsApply.js +13 -1
  47. package/lib/asset/AssetBytesGenerator.js +12 -8
  48. package/lib/asset/AssetGenerator.js +36 -22
  49. package/lib/asset/AssetModulesPlugin.js +6 -8
  50. package/lib/asset/AssetSourceGenerator.js +12 -8
  51. package/lib/buildChunkGraph.js +4 -6
  52. package/lib/cache/PackFileCacheStrategy.js +4 -4
  53. package/lib/cli.js +3 -1
  54. package/lib/config/defaults.js +197 -10
  55. package/lib/config/normalization.js +3 -1
  56. package/lib/css/CssGenerator.js +320 -105
  57. package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
  58. package/lib/css/CssLoadingRuntimeModule.js +22 -4
  59. package/lib/{CssModule.js → css/CssModule.js} +15 -15
  60. package/lib/css/CssModulesPlugin.js +168 -88
  61. package/lib/css/CssParser.js +566 -269
  62. package/lib/css/walkCssTokens.js +148 -2
  63. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
  64. package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
  65. package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
  66. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  67. package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
  68. package/lib/dependencies/CommonJsImportsParserPlugin.js +112 -4
  69. package/lib/dependencies/CommonJsRequireDependency.js +67 -4
  70. package/lib/dependencies/ContextDependency.js +1 -1
  71. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  72. package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
  73. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  74. package/lib/dependencies/CssIcssExportDependency.js +332 -67
  75. package/lib/dependencies/CssIcssImportDependency.js +49 -7
  76. package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
  77. package/lib/dependencies/CssImportDependency.js +8 -0
  78. package/lib/dependencies/CssUrlDependency.js +28 -2
  79. package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
  80. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
  81. package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
  82. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
  83. package/lib/dependencies/HarmonyImportDependency.js +10 -2
  84. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
  85. package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
  86. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
  87. package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
  88. package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
  89. package/lib/dependencies/HtmlScriptSrcDependency.js +557 -0
  90. package/lib/dependencies/HtmlSourceDependency.js +128 -0
  91. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  92. package/lib/dependencies/ImportParserPlugin.js +2 -2
  93. package/lib/dependencies/ImportPhase.js +1 -1
  94. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
  95. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
  96. package/lib/dependencies/SystemPlugin.js +1 -1
  97. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  98. package/lib/dependencies/WorkerPlugin.js +2 -2
  99. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
  100. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
  101. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
  102. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
  103. package/lib/{DllModule.js → dll/DllModule.js} +24 -24
  104. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
  105. package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
  106. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
  107. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
  108. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
  109. package/lib/errors/BuildCycleError.js +1 -1
  110. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  111. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  112. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
  113. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
  114. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
  115. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
  116. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
  117. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
  118. package/lib/errors/JSONParseError.js +114 -0
  119. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
  120. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
  121. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
  122. package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
  123. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
  124. package/lib/errors/ModuleNotFoundError.js +91 -0
  125. package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
  126. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
  127. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
  128. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
  129. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
  130. package/lib/errors/NonErrorEmittedError.js +28 -0
  131. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
  132. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
  133. package/lib/errors/WebpackError.js +84 -0
  134. package/lib/html/HtmlGenerator.js +379 -0
  135. package/lib/html/HtmlModulesPlugin.js +429 -0
  136. package/lib/html/HtmlParser.js +1489 -0
  137. package/lib/html/walkHtmlTokens.js +3249 -0
  138. package/lib/ids/IdHelpers.js +2 -1
  139. package/lib/index.js +36 -15
  140. package/lib/javascript/JavascriptModulesPlugin.js +91 -10
  141. package/lib/javascript/JavascriptParser.js +197 -16
  142. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  143. package/lib/json/JsonParser.js +7 -16
  144. package/lib/library/AbstractLibraryPlugin.js +1 -1
  145. package/lib/library/EnableLibraryPlugin.js +1 -1
  146. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
  147. package/lib/library/ModuleLibraryPlugin.js +74 -0
  148. package/lib/node/NodeEnvironmentPlugin.js +4 -2
  149. package/lib/node/nodeConsole.js +113 -64
  150. package/lib/optimize/ConcatenatedModule.js +51 -6
  151. package/lib/optimize/InnerGraph.js +1 -1
  152. package/lib/optimize/InnerGraphPlugin.js +11 -1
  153. package/lib/optimize/MinMaxSizeWarning.js +4 -4
  154. package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
  155. package/lib/optimize/RealContentHashPlugin.js +89 -26
  156. package/lib/optimize/SideEffectsFlagPlugin.js +112 -5
  157. package/lib/optimize/SplitChunksPlugin.js +5 -5
  158. package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
  159. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  160. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  161. package/lib/performance/SizeLimitsPlugin.js +1 -1
  162. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
  163. package/lib/rules/UseEffectRulePlugin.js +4 -3
  164. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -3
  165. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -5
  166. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
  167. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
  168. package/lib/schemes/DataUriPlugin.js +13 -1
  169. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  170. package/lib/serialization/SerializerMiddleware.js +2 -2
  171. package/lib/sharing/ConsumeSharedPlugin.js +4 -10
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  173. package/lib/sharing/ProvideSharedModule.js +1 -1
  174. package/lib/sharing/ProvideSharedPlugin.js +5 -5
  175. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  176. package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
  177. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  178. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  179. package/lib/stats/StatsFactory.js +1 -1
  180. package/lib/typescript/TypeScriptPlugin.js +210 -0
  181. package/lib/url/URLParserPlugin.js +2 -2
  182. package/lib/util/AsyncQueue.js +2 -2
  183. package/lib/util/Hash.js +2 -2
  184. package/lib/util/LocConverter.js +53 -0
  185. package/lib/util/SortableSet.js +1 -1
  186. package/lib/util/cleverMerge.js +2 -2
  187. package/lib/util/comparators.js +3 -3
  188. package/lib/util/concatenate.js +3 -3
  189. package/lib/util/conventions.js +42 -1
  190. package/lib/util/createMappings.js +118 -0
  191. package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
  192. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
  193. package/lib/util/fs.js +8 -8
  194. package/lib/util/hash/md4.js +1 -1
  195. package/lib/util/hash/xxhash64.js +1 -1
  196. package/lib/util/identifier.js +48 -0
  197. package/lib/util/internalSerializables.js +35 -19
  198. package/lib/util/magicComment.js +10 -7
  199. package/lib/util/parseJson.js +2 -73
  200. package/lib/util/source.js +21 -0
  201. package/lib/util/topologicalSort.js +69 -0
  202. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -4
  203. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  204. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
  205. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
  206. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
  207. package/lib/webpack.js +3 -1
  208. package/package.json +24 -22
  209. package/schemas/WebpackOptions.check.js +1 -1
  210. package/schemas/WebpackOptions.json +129 -12
  211. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  212. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  213. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/ProgressPlugin.json +22 -0
  216. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  217. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  218. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  219. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  220. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  221. package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
  222. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  223. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  224. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  225. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  226. package/types.d.ts +1153 -233
  227. package/lib/CaseSensitiveModulesWarning.js +0 -80
  228. package/lib/GraphHelpers.js +0 -49
  229. package/lib/NoModeWarning.js +0 -23
  230. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
  231. /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
  232. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  233. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  234. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  235. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -5,80 +5,6 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const inspect = require("util").inspect.custom;
9
- const makeSerializable = require("./util/makeSerializable");
10
-
11
- /** @typedef {import("./Chunk")} Chunk */
12
- /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
13
- /** @typedef {import("./Module")} Module */
14
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
-
17
- class WebpackError extends Error {
18
- /**
19
- * Creates an instance of WebpackError.
20
- * @param {string=} message error message
21
- * @param {{ cause?: unknown }} options error options
22
- */
23
- constructor(message, options = {}) {
24
- super(message, options);
25
-
26
- /** @type {string=} */
27
- this.details = undefined;
28
- /** @type {(Module | null)=} */
29
- this.module = undefined;
30
- /** @type {DependencyLocation=} */
31
- this.loc = undefined;
32
- /** @type {boolean=} */
33
- this.hideStack = undefined;
34
- /** @type {Chunk=} */
35
- this.chunk = undefined;
36
- /** @type {string=} */
37
- this.file = undefined;
38
- }
39
-
40
- /**
41
- * Returns inspect message.
42
- * @returns {string} inspect message
43
- */
44
- [inspect]() {
45
- return (
46
- this.stack +
47
- (this.details ? `\n${this.details}` : "") +
48
- (this.cause ? `\n${this.cause}` : "")
49
- );
50
- }
51
-
52
- /**
53
- * Serializes this instance into the provided serializer context.
54
- * @param {ObjectSerializerContext} context context
55
- */
56
- serialize({ write }) {
57
- write(this.name);
58
- write(this.message);
59
- write(this.stack);
60
- write(this.cause);
61
- write(this.details);
62
- write(this.loc);
63
- write(this.hideStack);
64
- }
65
-
66
- /**
67
- * Restores this instance from the provided deserializer context.
68
- * @param {ObjectDeserializerContext} context context
69
- */
70
- deserialize({ read }) {
71
- this.name = read();
72
- this.message = read();
73
- this.stack = read();
74
- this.cause = read();
75
- this.details = read();
76
- this.loc = read();
77
- this.hideStack = read();
78
- }
79
- }
80
-
81
- makeSerializable(WebpackError, "webpack/lib/WebpackError");
82
-
83
- /** @type {typeof WebpackError} */
84
- module.exports = WebpackError;
8
+ // TODO remove in webpack 6
9
+ // Some old plugins use `require("webpack/lib/WebpackError")`, in webpack@6 developer should migrate to `compiler.webpack.WebpackError`
10
+ module.exports = require("./errors/WebpackError");
@@ -5,13 +5,13 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const IgnoreErrorModuleFactory = require("./IgnoreErrorModuleFactory");
9
8
  const {
10
9
  JAVASCRIPT_MODULE_TYPE_AUTO,
11
10
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
12
11
  JAVASCRIPT_MODULE_TYPE_ESM
13
12
  } = require("./ModuleTypeConstants");
14
13
  const WebpackIsIncludedDependency = require("./dependencies/WebpackIsIncludedDependency");
14
+ const IgnoreErrorModuleFactory = require("./errors/IgnoreErrorModuleFactory");
15
15
  const {
16
16
  toConstantDependency
17
17
  } = require("./javascript/JavascriptParserHelpers");
@@ -425,6 +425,18 @@ class WebpackOptionsApply extends OptionsApply {
425
425
  new CssModulesPlugin().apply(compiler);
426
426
  }
427
427
 
428
+ if (options.experiments.html) {
429
+ const HtmlModulesPlugin = require("./html/HtmlModulesPlugin");
430
+
431
+ new HtmlModulesPlugin().apply(compiler);
432
+ }
433
+
434
+ if (options.experiments.typescript) {
435
+ const TypeScriptPlugin = require("./typescript/TypeScriptPlugin");
436
+
437
+ new TypeScriptPlugin().apply(compiler);
438
+ }
439
+
428
440
  if (options.experiments.lazyCompilation) {
429
441
  const LazyCompilationPlugin = require("./hmr/LazyCompilationPlugin");
430
442
 
@@ -517,7 +529,7 @@ class WebpackOptionsApply extends OptionsApply {
517
529
  }).apply(compiler);
518
530
  if (options.amd !== false) {
519
531
  const AMDPlugin = require("./dependencies/AMDPlugin");
520
- const RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
532
+ const RequireJsStuffPlugin = require("./dependencies/RequireJsStuffPlugin");
521
533
 
522
534
  new AMDPlugin(options.amd || {}).apply(compiler);
523
535
  new RequireJsStuffPlugin().apply(compiler);
@@ -9,10 +9,11 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const Generator = require("../Generator");
11
11
  const {
12
+ ASSET_URL_TYPE,
13
+ ASSET_URL_TYPES,
12
14
  CSS_TYPE,
13
- CSS_URL_TYPE,
14
- CSS_URL_TYPES,
15
- JAVASCRIPT_AND_CSS_URL_TYPES,
15
+ HTML_TYPE,
16
+ JAVASCRIPT_AND_ASSET_URL_TYPES,
16
17
  JAVASCRIPT_TYPE,
17
18
  JAVASCRIPT_TYPES,
18
19
  NO_TYPES
@@ -79,7 +80,7 @@ class AssetSourceGenerator extends Generator {
79
80
  }
80
81
  return new RawSource(sourceContent);
81
82
  }
82
- case CSS_URL_TYPE: {
83
+ case ASSET_URL_TYPE: {
83
84
  if (!originalSource) {
84
85
  return null;
85
86
  }
@@ -146,10 +147,13 @@ class AssetSourceGenerator extends Generator {
146
147
  }
147
148
 
148
149
  if (sourceTypes.size > 0) {
149
- if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
150
- return JAVASCRIPT_AND_CSS_URL_TYPES;
151
- } else if (sourceTypes.has(CSS_TYPE)) {
152
- return CSS_URL_TYPES;
150
+ if (
151
+ sourceTypes.has(JAVASCRIPT_TYPE) &&
152
+ (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE))
153
+ ) {
154
+ return JAVASCRIPT_AND_ASSET_URL_TYPES;
155
+ } else if (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE)) {
156
+ return ASSET_URL_TYPES;
153
157
  }
154
158
  return JAVASCRIPT_TYPES;
155
159
  }
@@ -10,14 +10,15 @@ const { RawSource } = require("webpack-sources");
10
10
  const ConcatenationScope = require("../ConcatenationScope");
11
11
  const Generator = require("../Generator");
12
12
  const {
13
- ASSET_AND_CSS_URL_TYPES,
14
- ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES,
13
+ ASSET_AND_ASSET_URL_TYPES,
14
+ ASSET_AND_JAVASCRIPT_AND_ASSET_URL_TYPES,
15
15
  ASSET_AND_JAVASCRIPT_TYPES,
16
16
  ASSET_TYPES,
17
+ ASSET_URL_TYPE,
18
+ ASSET_URL_TYPES,
17
19
  CSS_TYPE,
18
- CSS_URL_TYPE,
19
- CSS_URL_TYPES,
20
- JAVASCRIPT_AND_CSS_URL_TYPES,
20
+ HTML_TYPE,
21
+ JAVASCRIPT_AND_ASSET_URL_TYPES,
21
22
  JAVASCRIPT_TYPE,
22
23
  JAVASCRIPT_TYPES,
23
24
  NO_TYPES
@@ -29,6 +30,7 @@ const createHash = require("../util/createHash");
29
30
  const { makePathsRelative } = require("../util/identifier");
30
31
  const memoize = require("../util/memoize");
31
32
  const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
33
+ const { updateHashFromSource } = require("../util/source");
32
34
 
33
35
  const getMimeTypes = memoize(() => require("../util/mimeTypes"));
34
36
 
@@ -259,7 +261,7 @@ class AssetGenerator extends Generator {
259
261
  const source = module.originalSource();
260
262
 
261
263
  if (source) {
262
- hash.update(source.buffer());
264
+ updateHashFromSource(hash, source);
263
265
  }
264
266
 
265
267
  if (module.error) {
@@ -371,7 +373,7 @@ class AssetGenerator extends Generator {
371
373
  assetPath = JSON.stringify(path + filename);
372
374
  } else if (
373
375
  generatorOptions.publicPath !== undefined &&
374
- type === CSS_URL_TYPE
376
+ type === ASSET_URL_TYPE
375
377
  ) {
376
378
  const { path, info } = runtimeTemplate.compilation.getAssetPathWithInfo(
377
379
  generatorOptions.publicPath,
@@ -392,13 +394,19 @@ class AssetGenerator extends Generator {
392
394
  { expr: RuntimeGlobals.publicPath },
393
395
  filename
394
396
  );
395
- } else if (type === CSS_URL_TYPE) {
397
+ } else if (type === ASSET_URL_TYPE) {
396
398
  const compilation = runtimeTemplate.compilation;
397
399
  const path =
398
400
  compilation.outputOptions.publicPath === "auto"
399
401
  ? CssUrlDependency.PUBLIC_PATH_AUTO
400
402
  : compilation.getAssetPath(compilation.outputOptions.publicPath, {
401
- hash: compilation.hash
403
+ hash:
404
+ compilation.hash ||
405
+ `${CssUrlDependency.PUBLIC_PATH_FULL_HASH}0__`,
406
+ hashWithLength: (length) =>
407
+ compilation.hash
408
+ ? compilation.hash.slice(0, length)
409
+ : `${CssUrlDependency.PUBLIC_PATH_FULL_HASH}${length}__`
402
410
  });
403
411
 
404
412
  assetPath = path + filename;
@@ -552,7 +560,7 @@ class AssetGenerator extends Generator {
552
560
  /** @type {string} */
553
561
  let content;
554
562
 
555
- const needContent = type === JAVASCRIPT_TYPE || type === CSS_URL_TYPE;
563
+ const needContent = type === JAVASCRIPT_TYPE || type === ASSET_URL_TYPE;
556
564
  const data = getData ? getData() : undefined;
557
565
 
558
566
  if (
@@ -567,7 +575,7 @@ class AssetGenerator extends Generator {
567
575
  : encodedSource;
568
576
 
569
577
  if (data) {
570
- data.set("url", { [type]: content, ...data.get("url") });
578
+ data.set("url", { ...data.get("url"), [type]: content });
571
579
  }
572
580
  } else {
573
581
  const [fullContentHash, contentHash] = AssetGenerator.getFullContentHash(
@@ -605,8 +613,8 @@ class AssetGenerator extends Generator {
605
613
  contentHash
606
614
  );
607
615
 
608
- if (data && (type === JAVASCRIPT_TYPE || type === CSS_URL_TYPE)) {
609
- data.set("url", { [type]: assetPath, ...data.get("url") });
616
+ if (data && (type === JAVASCRIPT_TYPE || type === ASSET_URL_TYPE)) {
617
+ data.set("url", { ...data.get("url"), [type]: assetPath });
610
618
  }
611
619
 
612
620
  if (data) {
@@ -649,7 +657,7 @@ class AssetGenerator extends Generator {
649
657
  runtimeRequirements.add(RuntimeGlobals.module);
650
658
 
651
659
  return new RawSource(`${module.moduleArgument}.exports = ${content};`);
652
- } else if (type === CSS_URL_TYPE) {
660
+ } else if (type === ASSET_URL_TYPE) {
653
661
  return null;
654
662
  }
655
663
 
@@ -698,10 +706,13 @@ class AssetGenerator extends Generator {
698
706
 
699
707
  if ((module.buildInfo && module.buildInfo.dataUrl) || this.emit === false) {
700
708
  if (sourceTypes.size > 0) {
701
- if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
702
- return JAVASCRIPT_AND_CSS_URL_TYPES;
703
- } else if (sourceTypes.has(CSS_TYPE)) {
704
- return CSS_URL_TYPES;
709
+ if (
710
+ sourceTypes.has(JAVASCRIPT_TYPE) &&
711
+ (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE))
712
+ ) {
713
+ return JAVASCRIPT_AND_ASSET_URL_TYPES;
714
+ } else if (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE)) {
715
+ return ASSET_URL_TYPES;
705
716
  }
706
717
  return JAVASCRIPT_TYPES;
707
718
  }
@@ -710,10 +721,13 @@ class AssetGenerator extends Generator {
710
721
  }
711
722
 
712
723
  if (sourceTypes.size > 0) {
713
- if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
714
- return ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES;
715
- } else if (sourceTypes.has(CSS_TYPE)) {
716
- return ASSET_AND_CSS_URL_TYPES;
724
+ if (
725
+ sourceTypes.has(JAVASCRIPT_TYPE) &&
726
+ (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE))
727
+ ) {
728
+ return ASSET_AND_JAVASCRIPT_AND_ASSET_URL_TYPES;
729
+ } else if (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE)) {
730
+ return ASSET_AND_ASSET_URL_TYPES;
717
731
  }
718
732
  return ASSET_AND_JAVASCRIPT_TYPES;
719
733
  }
@@ -20,13 +20,12 @@ const memoize = require("../util/memoize");
20
20
  /** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorDataUrl} AssetGeneratorDataUrl */
21
21
  /** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
22
22
  /** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
23
- /** @typedef {import("../../declarations/WebpackOptions").FilenameTemplate} FilenameTemplate */
23
+ /** @typedef {import("../../declarations/WebpackOptions").AssetModuleFilename} AssetModuleFilename */
24
24
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
25
25
  /** @typedef {import("../Compiler")} Compiler */
26
26
  /** @typedef {import("../Module").BuildInfo} BuildInfo */
27
27
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
28
28
  /** @typedef {import("../NormalModule")} NormalModule */
29
- /** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
30
29
 
31
30
  /**
32
31
  * Returns definition.
@@ -34,7 +33,9 @@ const memoize = require("../util/memoize");
34
33
  * @returns {Schema} definition
35
34
  */
36
35
  const getSchema = (name) => {
37
- const { definitions } = require("../../schemas/WebpackOptions.json");
36
+ const { definitions } =
37
+ /** @type {EXPECTED_ANY} */
38
+ (require("../../schemas/WebpackOptions.json"));
38
39
 
39
40
  return {
40
41
  definitions,
@@ -96,10 +97,7 @@ class AssetModulesPlugin {
96
97
  .for(type)
97
98
  .tap(PLUGIN_NAME, (createData, _resolveData) => {
98
99
  // TODO create the module via new AssetModule with its own properties
99
- const module = new NormalModule(
100
- /** @type {NormalModuleCreateData} */
101
- (createData)
102
- );
100
+ const module = new NormalModule(createData);
103
101
  if (this.options.sideEffectFree) {
104
102
  module.factoryMeta = { sideEffectFree: true };
105
103
  }
@@ -225,7 +223,7 @@ class AssetModulesPlugin {
225
223
  }
226
224
  }
227
225
 
228
- /** @type {undefined | FilenameTemplate} */
226
+ /** @type {undefined | AssetModuleFilename} */
229
227
  let filename;
230
228
  /** @type {undefined | RawPublicPath} */
231
229
  let publicPath;
@@ -9,10 +9,11 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const Generator = require("../Generator");
11
11
  const {
12
+ ASSET_URL_TYPE,
13
+ ASSET_URL_TYPES,
12
14
  CSS_TYPE,
13
- CSS_URL_TYPE,
14
- CSS_URL_TYPES,
15
- JAVASCRIPT_AND_CSS_URL_TYPES,
15
+ HTML_TYPE,
16
+ JAVASCRIPT_AND_ASSET_URL_TYPES,
16
17
  JAVASCRIPT_TYPE,
17
18
  JAVASCRIPT_TYPES,
18
19
  NO_TYPES
@@ -78,7 +79,7 @@ class AssetSourceGenerator extends Generator {
78
79
  }
79
80
  return new RawSource(sourceContent);
80
81
  }
81
- case CSS_URL_TYPE: {
82
+ case ASSET_URL_TYPE: {
82
83
  if (!originalSource) {
83
84
  return null;
84
85
  }
@@ -145,10 +146,13 @@ class AssetSourceGenerator extends Generator {
145
146
  }
146
147
 
147
148
  if (sourceTypes.size > 0) {
148
- if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
149
- return JAVASCRIPT_AND_CSS_URL_TYPES;
150
- } else if (sourceTypes.has(CSS_TYPE)) {
151
- return CSS_URL_TYPES;
149
+ if (
150
+ sourceTypes.has(JAVASCRIPT_TYPE) &&
151
+ (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE))
152
+ ) {
153
+ return JAVASCRIPT_AND_ASSET_URL_TYPES;
154
+ } else if (sourceTypes.has(CSS_TYPE) || sourceTypes.has(HTML_TYPE)) {
155
+ return ASSET_URL_TYPES;
152
156
  }
153
157
  return JAVASCRIPT_TYPES;
154
158
  }
@@ -5,9 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const AsyncDependencyToInitialChunkError = require("./AsyncDependencyToInitialChunkError");
9
- const { connectChunkGroupParentAndChild } = require("./GraphHelpers");
10
8
  const ModuleGraphConnection = require("./ModuleGraphConnection");
9
+ const AsyncDependencyToInitialChunkError = require("./errors/AsyncDependencyToInitialChunkError");
11
10
  const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
12
11
 
13
12
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
@@ -1311,10 +1310,9 @@ const connectChunkGroups = (
1311
1310
  chunkGraph.connectBlockAndChunkGroup(block, chunkGroup);
1312
1311
 
1313
1312
  // 4. Connect chunk with parent
1314
- connectChunkGroupParentAndChild(
1315
- originChunkGroupInfo.chunkGroup,
1316
- chunkGroup
1317
- );
1313
+ if (originChunkGroupInfo.chunkGroup.addChild(chunkGroup)) {
1314
+ chunkGroup.addParent(originChunkGroupInfo.chunkGroup);
1315
+ }
1318
1316
  }
1319
1317
  }
1320
1318
  };
@@ -7,9 +7,9 @@
7
7
 
8
8
  const FileSystemInfo = require("../FileSystemInfo");
9
9
  const ProgressPlugin = require("../ProgressPlugin");
10
- const { formatSize } = require("../SizeFormatHelpers");
11
10
  const SerializerMiddleware = require("../serialization/SerializerMiddleware");
12
11
  const LazySet = require("../util/LazySet");
12
+ const formatSize = require("../util/formatSize");
13
13
  const makeSerializable = require("../util/makeSerializable");
14
14
  const memoize = require("../util/memoize");
15
15
  const {
@@ -105,7 +105,7 @@ const MIN_CONTENT_SIZE = 1024 * 1024; // 1 MB
105
105
  const CONTENT_COUNT_TO_MERGE = 10;
106
106
  const MIN_ITEMS_IN_FRESH_PACK = 100;
107
107
  const MAX_ITEMS_IN_FRESH_PACK = 50000;
108
- const MAX_TIME_IN_FRESH_PACK = 1 * 60 * 1000; // 1 min
108
+ const MAX_TIME_IN_FRESH_PACK = 60 * 1000; // 1 min
109
109
 
110
110
  class PackItemInfo {
111
111
  /**
@@ -799,7 +799,7 @@ class PackContentItems {
799
799
  if (read()) {
800
800
  this.map = read();
801
801
  } else if (profile) {
802
- /** @type {Map<EXPECTED_ANY, EXPECTED_ANY>} */
802
+ /** @type {Content} */
803
803
  const map = new Map();
804
804
  let key = read();
805
805
  while (key !== null) {
@@ -825,7 +825,7 @@ class PackContentItems {
825
825
  }
826
826
  this.map = map;
827
827
  } else {
828
- /** @type {Map<EXPECTED_ANY, EXPECTED_ANY>} */
828
+ /** @type {Content} */
829
829
  const map = new Map();
830
830
  let key = read();
831
831
  while (key !== null) {
package/lib/cli.js CHANGED
@@ -7,7 +7,9 @@
7
7
 
8
8
  const path = require("path");
9
9
  const tty = require("tty");
10
- const webpackSchema = require("../schemas/WebpackOptions.json");
10
+ const webpackSchema =
11
+ /** @type {EXPECTED_ANY} */
12
+ (require("../schemas/WebpackOptions.json"));
11
13
 
12
14
  /** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */
13
15
  /** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */