webpack 5.59.0 → 5.71.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (209) hide show
  1. package/README.md +1 -7
  2. package/hot/lazy-compilation-node.js +3 -1
  3. package/hot/poll.js +1 -1
  4. package/hot/signal.js +1 -1
  5. package/lib/APIPlugin.js +33 -0
  6. package/lib/BannerPlugin.js +10 -4
  7. package/lib/Cache.js +1 -1
  8. package/lib/CacheFacade.js +4 -11
  9. package/lib/Chunk.js +6 -3
  10. package/lib/ChunkGraph.js +1 -2
  11. package/lib/ChunkGroup.js +1 -1
  12. package/lib/CleanPlugin.js +81 -20
  13. package/lib/Compilation.js +179 -91
  14. package/lib/Compiler.js +86 -17
  15. package/lib/ConstPlugin.js +2 -2
  16. package/lib/ContextModule.js +142 -51
  17. package/lib/ContextModuleFactory.js +65 -25
  18. package/lib/DelegatedModule.js +1 -1
  19. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  20. package/lib/Dependency.js +17 -0
  21. package/lib/DependencyTemplate.js +9 -0
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllModule.js +1 -1
  24. package/lib/EntryOptionPlugin.js +2 -0
  25. package/lib/ErrorHelpers.js +2 -2
  26. package/lib/EvalDevToolModulePlugin.js +16 -1
  27. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  28. package/lib/ExportsInfo.js +4 -4
  29. package/lib/ExternalModule.js +94 -54
  30. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  31. package/lib/FileSystemInfo.js +89 -44
  32. package/lib/Generator.js +3 -0
  33. package/lib/HookWebpackError.js +1 -1
  34. package/lib/HotModuleReplacementPlugin.js +3 -1
  35. package/lib/LoaderOptionsPlugin.js +1 -1
  36. package/lib/Module.js +27 -4
  37. package/lib/ModuleFilenameHelpers.js +8 -4
  38. package/lib/ModuleHashingError.js +29 -0
  39. package/lib/MultiCompiler.js +1 -1
  40. package/lib/MultiWatching.js +1 -1
  41. package/lib/NodeStuffPlugin.js +10 -0
  42. package/lib/NormalModule.js +41 -26
  43. package/lib/NormalModuleFactory.js +42 -37
  44. package/lib/ProgressPlugin.js +4 -5
  45. package/lib/RawModule.js +1 -1
  46. package/lib/RuntimeGlobals.js +29 -1
  47. package/lib/RuntimeModule.js +1 -1
  48. package/lib/RuntimePlugin.js +77 -1
  49. package/lib/RuntimeTemplate.js +114 -2
  50. package/lib/Template.js +2 -1
  51. package/lib/TemplatedPathPlugin.js +48 -23
  52. package/lib/WatchIgnorePlugin.js +19 -7
  53. package/lib/Watching.js +33 -19
  54. package/lib/WebpackOptionsApply.js +57 -11
  55. package/lib/asset/AssetGenerator.js +193 -63
  56. package/lib/asset/AssetModulesPlugin.js +3 -0
  57. package/lib/asset/RawDataUrlModule.js +148 -0
  58. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  59. package/lib/buildChunkGraph.js +36 -6
  60. package/lib/cache/PackFileCacheStrategy.js +7 -4
  61. package/lib/cache/ResolverCachePlugin.js +90 -29
  62. package/lib/cli.js +44 -3
  63. package/lib/config/browserslistTargetHandler.js +41 -6
  64. package/lib/config/defaults.js +115 -19
  65. package/lib/config/normalization.js +9 -0
  66. package/lib/config/target.js +10 -0
  67. package/lib/container/ContainerEntryModule.js +8 -5
  68. package/lib/container/FallbackModule.js +4 -4
  69. package/lib/container/RemoteModule.js +4 -2
  70. package/lib/css/CssExportsGenerator.js +139 -0
  71. package/lib/css/CssGenerator.js +109 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  73. package/lib/css/CssModulesPlugin.js +462 -0
  74. package/lib/css/CssParser.js +618 -0
  75. package/lib/css/walkCssTokens.js +659 -0
  76. package/lib/debug/ProfilingPlugin.js +24 -21
  77. package/lib/dependencies/AMDRequireDependency.js +6 -6
  78. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  79. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  80. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
  81. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  82. package/lib/dependencies/ContextDependency.js +1 -0
  83. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  84. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  85. package/lib/dependencies/ContextElementDependency.js +41 -3
  86. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  87. package/lib/dependencies/CssExportDependency.js +85 -0
  88. package/lib/dependencies/CssImportDependency.js +75 -0
  89. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  90. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  91. package/lib/dependencies/CssUrlDependency.js +132 -0
  92. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  93. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  94. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  95. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  96. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  97. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  98. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  99. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  100. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  102. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  103. package/lib/dependencies/ImportContextDependency.js +0 -2
  104. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  105. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  106. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  107. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  108. package/lib/dependencies/LoaderPlugin.js +4 -2
  109. package/lib/dependencies/RequireContextDependency.js +0 -16
  110. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  111. package/lib/dependencies/URLDependency.js +3 -8
  112. package/lib/dependencies/URLPlugin.js +1 -1
  113. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  114. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  115. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  116. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  117. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  118. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  119. package/lib/hmr/lazyCompilationBackend.js +51 -12
  120. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  121. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  122. package/lib/ids/IdHelpers.js +25 -11
  123. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  124. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  125. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  126. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  127. package/lib/index.js +13 -0
  128. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  129. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  130. package/lib/javascript/ChunkHelpers.js +33 -0
  131. package/lib/javascript/JavascriptGenerator.js +1 -0
  132. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  133. package/lib/javascript/JavascriptParser.js +82 -48
  134. package/lib/javascript/StartupHelpers.js +7 -30
  135. package/lib/library/AssignLibraryPlugin.js +39 -15
  136. package/lib/library/EnableLibraryPlugin.js +11 -0
  137. package/lib/library/UmdLibraryPlugin.js +5 -3
  138. package/lib/node/NodeTargetPlugin.js +3 -0
  139. package/lib/node/NodeWatchFileSystem.js +85 -31
  140. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  141. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  142. package/lib/optimize/ConcatenatedModule.js +21 -9
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  144. package/lib/optimize/SplitChunksPlugin.js +8 -1
  145. package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
  146. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  147. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  148. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  149. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  150. package/lib/schemes/HttpUriPlugin.js +77 -14
  151. package/lib/serialization/FileMiddleware.js +44 -9
  152. package/lib/sharing/ConsumeSharedModule.js +8 -2
  153. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  154. package/lib/sharing/ProvideSharedModule.js +4 -2
  155. package/lib/sharing/ShareRuntimeModule.js +1 -1
  156. package/lib/sharing/utils.js +1 -1
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  158. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  159. package/lib/util/ArrayHelpers.js +30 -0
  160. package/lib/util/AsyncQueue.js +1 -1
  161. package/lib/util/compileBooleanMatcher.js +1 -1
  162. package/lib/util/create-schema-validation.js +9 -2
  163. package/lib/util/createHash.js +12 -0
  164. package/lib/util/deprecation.js +10 -2
  165. package/lib/util/deterministicGrouping.js +1 -1
  166. package/lib/util/extractUrlAndGlobal.js +3 -0
  167. package/lib/util/fs.js +11 -0
  168. package/lib/util/hash/BatchedHash.js +7 -4
  169. package/lib/util/hash/md4.js +20 -0
  170. package/lib/util/hash/wasm-hash.js +163 -0
  171. package/lib/util/hash/xxhash64.js +5 -139
  172. package/lib/util/identifier.js +65 -44
  173. package/lib/util/internalSerializables.js +15 -0
  174. package/lib/util/nonNumericOnlyHash.js +22 -0
  175. package/lib/util/semver.js +17 -10
  176. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  177. package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
  178. package/lib/webpack.js +10 -3
  179. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  180. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  181. package/module.d.ts +215 -0
  182. package/package.json +23 -28
  183. package/schemas/WebpackOptions.check.js +1 -1
  184. package/schemas/WebpackOptions.json +254 -29
  185. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  186. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  187. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  188. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  189. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  190. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  191. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  192. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  194. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  195. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  197. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  198. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  199. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  200. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  201. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  202. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  203. package/schemas/plugins/css/CssParserOptions.json +3 -0
  204. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  209. package/types.d.ts +628 -179
@@ -12,9 +12,11 @@ const Generator = require("../Generator");
12
12
  const RuntimeGlobals = require("../RuntimeGlobals");
13
13
  const createHash = require("../util/createHash");
14
14
  const { makePathsRelative } = require("../util/identifier");
15
+ const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
15
16
 
16
17
  /** @typedef {import("webpack-sources").Source} Source */
17
18
  /** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
19
+ /** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
18
20
  /** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
19
21
  /** @typedef {import("../Compilation")} Compilation */
20
22
  /** @typedef {import("../Compiler")} Compiler */
@@ -49,7 +51,7 @@ const mergeAssetInfo = (a, b) => {
49
51
  case "immutable":
50
52
  case "development":
51
53
  case "hotModuleReplacement":
52
- case "javascriptModule ":
54
+ case "javascriptModule":
53
55
  result[key] = a[key] || b[key];
54
56
  break;
55
57
  case "related":
@@ -74,24 +76,121 @@ const mergeRelatedInfo = (a, b) => {
74
76
  return result;
75
77
  };
76
78
 
79
+ const encodeDataUri = (encoding, source) => {
80
+ let encodedContent;
81
+
82
+ switch (encoding) {
83
+ case "base64": {
84
+ encodedContent = source.buffer().toString("base64");
85
+ break;
86
+ }
87
+ case false: {
88
+ const content = source.source();
89
+
90
+ if (typeof content !== "string") {
91
+ encodedContent = content.toString("utf-8");
92
+ }
93
+
94
+ encodedContent = encodeURIComponent(encodedContent).replace(
95
+ /[!'()*]/g,
96
+ character => "%" + character.codePointAt(0).toString(16)
97
+ );
98
+ break;
99
+ }
100
+ default:
101
+ throw new Error(`Unsupported encoding '${encoding}'`);
102
+ }
103
+
104
+ return encodedContent;
105
+ };
106
+
107
+ const decodeDataUriContent = (encoding, content) => {
108
+ const isBase64 = encoding === "base64";
109
+ return isBase64
110
+ ? Buffer.from(content, "base64")
111
+ : Buffer.from(decodeURIComponent(content), "ascii");
112
+ };
113
+
77
114
  const JS_TYPES = new Set(["javascript"]);
78
115
  const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]);
116
+ const DEFAULT_ENCODING = "base64";
79
117
 
80
118
  class AssetGenerator extends Generator {
81
119
  /**
82
120
  * @param {AssetGeneratorOptions["dataUrl"]=} dataUrlOptions the options for the data url
83
121
  * @param {string=} filename override for output.assetModuleFilename
84
122
  * @param {RawPublicPath=} publicPath override for output.assetModulePublicPath
123
+ * @param {AssetModuleOutputPath=} outputPath the output path for the emitted file which is not included in the runtime import
85
124
  * @param {boolean=} emit generate output asset
86
125
  */
87
- constructor(dataUrlOptions, filename, publicPath, emit) {
126
+ constructor(dataUrlOptions, filename, publicPath, outputPath, emit) {
88
127
  super();
89
128
  this.dataUrlOptions = dataUrlOptions;
90
129
  this.filename = filename;
91
130
  this.publicPath = publicPath;
131
+ this.outputPath = outputPath;
92
132
  this.emit = emit;
93
133
  }
94
134
 
135
+ /**
136
+ * @param {NormalModule} module module
137
+ * @param {RuntimeTemplate} runtimeTemplate runtime template
138
+ * @returns {string} source file name
139
+ */
140
+ getSourceFileName(module, runtimeTemplate) {
141
+ return makePathsRelative(
142
+ runtimeTemplate.compilation.compiler.context,
143
+ module.matchResource || module.resource,
144
+ runtimeTemplate.compilation.compiler.root
145
+ ).replace(/^\.\//, "");
146
+ }
147
+
148
+ /**
149
+ * @param {NormalModule} module module
150
+ * @returns {string} mime type
151
+ */
152
+ getMimeType(module) {
153
+ if (typeof this.dataUrlOptions === "function") {
154
+ throw new Error(
155
+ "This method must not be called when dataUrlOptions is a function"
156
+ );
157
+ }
158
+
159
+ let mimeType = this.dataUrlOptions.mimetype;
160
+ if (mimeType === undefined) {
161
+ const ext = path.extname(module.nameForCondition());
162
+ if (
163
+ module.resourceResolveData &&
164
+ module.resourceResolveData.mimetype !== undefined
165
+ ) {
166
+ mimeType =
167
+ module.resourceResolveData.mimetype +
168
+ module.resourceResolveData.parameters;
169
+ } else if (ext) {
170
+ mimeType = mimeTypes.lookup(ext);
171
+
172
+ if (typeof mimeType !== "string") {
173
+ throw new Error(
174
+ "DataUrl can't be generated automatically, " +
175
+ `because there is no mimetype for "${ext}" in mimetype database. ` +
176
+ 'Either pass a mimetype via "generator.mimetype" or ' +
177
+ 'use type: "asset/resource" to create a resource file instead of a DataUrl'
178
+ );
179
+ }
180
+ }
181
+ }
182
+
183
+ if (typeof mimeType !== "string") {
184
+ throw new Error(
185
+ "DataUrl can't be generated automatically. " +
186
+ 'Either pass a mimetype via "generator.mimetype" or ' +
187
+ 'use type: "asset/resource" to create a resource file instead of a DataUrl'
188
+ );
189
+ }
190
+
191
+ return mimeType;
192
+ }
193
+
95
194
  /**
96
195
  * @param {NormalModule} module module for which the code should be generated
97
196
  * @param {GenerateContext} generateContext context for generate
@@ -131,66 +230,31 @@ class AssetGenerator extends Generator {
131
230
  }
132
231
  }
133
232
  if (encoding === undefined) {
134
- encoding = "base64";
135
- }
136
- let ext;
137
- let mimeType = this.dataUrlOptions.mimetype;
138
- if (mimeType === undefined) {
139
- ext = path.extname(module.nameForCondition());
140
- if (
141
- module.resourceResolveData &&
142
- module.resourceResolveData.mimetype !== undefined
143
- ) {
144
- mimeType =
145
- module.resourceResolveData.mimetype +
146
- module.resourceResolveData.parameters;
147
- } else if (ext) {
148
- mimeType = mimeTypes.lookup(ext);
149
- }
150
- }
151
- if (typeof mimeType !== "string") {
152
- throw new Error(
153
- "DataUrl can't be generated automatically, " +
154
- `because there is no mimetype for "${ext}" in mimetype database. ` +
155
- 'Either pass a mimetype via "generator.mimetype" or ' +
156
- 'use type: "asset/resource" to create a resource file instead of a DataUrl'
157
- );
233
+ encoding = DEFAULT_ENCODING;
158
234
  }
235
+ const mimeType = this.getMimeType(module);
159
236
 
160
237
  let encodedContent;
238
+
161
239
  if (
162
240
  module.resourceResolveData &&
163
- module.resourceResolveData.encoding === encoding
241
+ module.resourceResolveData.encoding === encoding &&
242
+ decodeDataUriContent(
243
+ module.resourceResolveData.encoding,
244
+ module.resourceResolveData.encodedContent
245
+ ).equals(originalSource.buffer())
164
246
  ) {
165
247
  encodedContent = module.resourceResolveData.encodedContent;
166
248
  } else {
167
- switch (encoding) {
168
- case "base64": {
169
- encodedContent = originalSource.buffer().toString("base64");
170
- break;
171
- }
172
- case false: {
173
- const content = originalSource.source();
174
-
175
- if (typeof content !== "string") {
176
- encodedContent = content.toString("utf-8");
177
- }
178
-
179
- encodedContent = encodeURIComponent(encodedContent).replace(
180
- /[!'()*]/g,
181
- character => "%" + character.codePointAt(0).toString(16)
182
- );
183
- break;
184
- }
185
- default:
186
- throw new Error(`Unsupported encoding '${encoding}'`);
187
- }
249
+ encodedContent = encodeDataUri(encoding, originalSource);
188
250
  }
189
251
 
190
252
  encodedSource = `data:${mimeType}${
191
253
  encoding ? `;${encoding}` : ""
192
254
  },${encodedContent}`;
193
255
  }
256
+ const data = getData();
257
+ data.set("url", Buffer.from(encodedSource));
194
258
  return new RawSource(
195
259
  `${RuntimeGlobals.module}.exports = ${JSON.stringify(
196
260
  encodedSource
@@ -207,16 +271,15 @@ class AssetGenerator extends Generator {
207
271
  const fullHash = /** @type {string} */ (
208
272
  hash.digest(runtimeTemplate.outputOptions.hashDigest)
209
273
  );
210
- const contentHash = fullHash.slice(
211
- 0,
274
+ const contentHash = nonNumericOnlyHash(
275
+ fullHash,
212
276
  runtimeTemplate.outputOptions.hashDigestLength
213
277
  );
214
278
  module.buildInfo.fullContentHash = fullHash;
215
- const sourceFilename = makePathsRelative(
216
- runtimeTemplate.compilation.compiler.context,
217
- module.matchResource || module.resource,
218
- runtimeTemplate.compilation.compiler.root
219
- ).replace(/^\.\//, "");
279
+ const sourceFilename = this.getSourceFileName(
280
+ module,
281
+ runtimeTemplate
282
+ );
220
283
  let { path: filename, info: assetInfo } =
221
284
  runtimeTemplate.compilation.getAssetPathWithInfo(
222
285
  assetModuleFilename,
@@ -228,7 +291,7 @@ class AssetGenerator extends Generator {
228
291
  contentHash
229
292
  }
230
293
  );
231
- let publicPath;
294
+ let assetPath;
232
295
  if (this.publicPath !== undefined) {
233
296
  const { path, info } =
234
297
  runtimeTemplate.compilation.getAssetPathWithInfo(
@@ -241,16 +304,34 @@ class AssetGenerator extends Generator {
241
304
  contentHash
242
305
  }
243
306
  );
244
- publicPath = JSON.stringify(path);
245
307
  assetInfo = mergeAssetInfo(assetInfo, info);
308
+ assetPath = JSON.stringify(path + filename);
246
309
  } else {
247
- publicPath = RuntimeGlobals.publicPath;
248
310
  runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
311
+ assetPath = runtimeTemplate.concatenation(
312
+ { expr: RuntimeGlobals.publicPath },
313
+ filename
314
+ );
249
315
  }
250
316
  assetInfo = {
251
317
  sourceFilename,
252
318
  ...assetInfo
253
319
  };
320
+ if (this.outputPath) {
321
+ const { path: outputPath, info } =
322
+ runtimeTemplate.compilation.getAssetPathWithInfo(
323
+ this.outputPath,
324
+ {
325
+ module,
326
+ runtime,
327
+ filename: sourceFilename,
328
+ chunkGraph,
329
+ contentHash
330
+ }
331
+ );
332
+ assetInfo = mergeAssetInfo(assetInfo, info);
333
+ filename = path.posix.join(outputPath, filename);
334
+ }
254
335
  module.buildInfo.filename = filename;
255
336
  module.buildInfo.assetInfo = assetInfo;
256
337
  if (getData) {
@@ -264,9 +345,7 @@ class AssetGenerator extends Generator {
264
345
  }
265
346
 
266
347
  return new RawSource(
267
- `${
268
- RuntimeGlobals.module
269
- }.exports = ${publicPath} + ${JSON.stringify(filename)};`
348
+ `${RuntimeGlobals.module}.exports = ${assetPath};`
270
349
  );
271
350
  }
272
351
  }
@@ -326,8 +405,59 @@ class AssetGenerator extends Generator {
326
405
  * @param {Hash} hash hash that will be modified
327
406
  * @param {UpdateHashContext} updateHashContext context for updating hash
328
407
  */
329
- updateHash(hash, { module }) {
330
- hash.update(module.buildInfo.dataUrl ? "data-url" : "resource");
408
+ updateHash(hash, { module, runtime, runtimeTemplate, chunkGraph }) {
409
+ if (module.buildInfo.dataUrl) {
410
+ hash.update("data-url");
411
+ // this.dataUrlOptions as function should be pure and only depend on input source and filename
412
+ // therefore it doesn't need to be hashed
413
+ if (typeof this.dataUrlOptions === "function") {
414
+ const ident = /** @type {{ ident?: string }} */ (this.dataUrlOptions)
415
+ .ident;
416
+ if (ident) hash.update(ident);
417
+ } else {
418
+ if (
419
+ this.dataUrlOptions.encoding &&
420
+ this.dataUrlOptions.encoding !== DEFAULT_ENCODING
421
+ ) {
422
+ hash.update(this.dataUrlOptions.encoding);
423
+ }
424
+ if (this.dataUrlOptions.mimetype)
425
+ hash.update(this.dataUrlOptions.mimetype);
426
+ // computed mimetype depends only on module filename which is already part of the hash
427
+ }
428
+ } else {
429
+ hash.update("resource");
430
+
431
+ const pathData = {
432
+ module,
433
+ runtime,
434
+ filename: this.getSourceFileName(module, runtimeTemplate),
435
+ chunkGraph,
436
+ contentHash: runtimeTemplate.contentHashReplacement
437
+ };
438
+
439
+ if (typeof this.publicPath === "function") {
440
+ hash.update("path");
441
+ const assetInfo = {};
442
+ hash.update(this.publicPath(pathData, assetInfo));
443
+ hash.update(JSON.stringify(assetInfo));
444
+ } else if (this.publicPath) {
445
+ hash.update("path");
446
+ hash.update(this.publicPath);
447
+ } else {
448
+ hash.update("no-path");
449
+ }
450
+
451
+ const assetModuleFilename =
452
+ this.filename || runtimeTemplate.outputOptions.assetModuleFilename;
453
+ const { path: filename, info } =
454
+ runtimeTemplate.compilation.getAssetPathWithInfo(
455
+ assetModuleFilename,
456
+ pathData
457
+ );
458
+ hash.update(filename);
459
+ hash.update(JSON.stringify(info));
460
+ }
331
461
  }
332
462
  }
333
463
 
@@ -137,9 +137,11 @@ class AssetModulesPlugin {
137
137
 
138
138
  let filename = undefined;
139
139
  let publicPath = undefined;
140
+ let outputPath = undefined;
140
141
  if (type !== "asset/inline") {
141
142
  filename = generatorOptions.filename;
142
143
  publicPath = generatorOptions.publicPath;
144
+ outputPath = generatorOptions.outputPath;
143
145
  }
144
146
 
145
147
  const AssetGenerator = getAssetGenerator();
@@ -148,6 +150,7 @@ class AssetModulesPlugin {
148
150
  dataUrl,
149
151
  filename,
150
152
  publicPath,
153
+ outputPath,
151
154
  generatorOptions.emit !== false
152
155
  );
153
156
  });
@@ -0,0 +1,148 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { RawSource } = require("webpack-sources");
9
+ const Module = require("../Module");
10
+ const RuntimeGlobals = require("../RuntimeGlobals");
11
+ const makeSerializable = require("../util/makeSerializable");
12
+
13
+ /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
14
+ /** @typedef {import("../Compilation")} Compilation */
15
+ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
16
+ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
17
+ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
18
+ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
19
+ /** @typedef {import("../RequestShortener")} RequestShortener */
20
+ /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
21
+ /** @typedef {import("../WebpackError")} WebpackError */
22
+ /** @typedef {import("../util/Hash")} Hash */
23
+ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
24
+
25
+ const TYPES = new Set(["javascript"]);
26
+
27
+ class RawDataUrlModule extends Module {
28
+ /**
29
+ * @param {string} url raw url
30
+ * @param {string} identifier unique identifier
31
+ * @param {string=} readableIdentifier readable identifier
32
+ */
33
+ constructor(url, identifier, readableIdentifier) {
34
+ super("asset/raw-data-url", null);
35
+ this.url = url;
36
+ this.urlBuffer = url ? Buffer.from(url) : undefined;
37
+ this.identifierStr = identifier || this.url;
38
+ this.readableIdentifierStr = readableIdentifier || this.identifierStr;
39
+ }
40
+
41
+ /**
42
+ * @returns {Set<string>} types available (do not mutate)
43
+ */
44
+ getSourceTypes() {
45
+ return TYPES;
46
+ }
47
+
48
+ /**
49
+ * @returns {string} a unique identifier of the module
50
+ */
51
+ identifier() {
52
+ return this.identifierStr;
53
+ }
54
+
55
+ /**
56
+ * @param {string=} type the source type for which the size should be estimated
57
+ * @returns {number} the estimated size of the module (must be non-zero)
58
+ */
59
+ size(type) {
60
+ if (this.url === undefined) this.url = this.urlBuffer.toString();
61
+ return Math.max(1, this.url.length);
62
+ }
63
+
64
+ /**
65
+ * @param {RequestShortener} requestShortener the request shortener
66
+ * @returns {string} a user readable identifier of the module
67
+ */
68
+ readableIdentifier(requestShortener) {
69
+ return requestShortener.shorten(this.readableIdentifierStr);
70
+ }
71
+
72
+ /**
73
+ * @param {NeedBuildContext} context context info
74
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
75
+ * @returns {void}
76
+ */
77
+ needBuild(context, callback) {
78
+ return callback(null, !this.buildMeta);
79
+ }
80
+
81
+ /**
82
+ * @param {WebpackOptions} options webpack options
83
+ * @param {Compilation} compilation the compilation
84
+ * @param {ResolverWithOptions} resolver the resolver
85
+ * @param {InputFileSystem} fs the file system
86
+ * @param {function(WebpackError=): void} callback callback function
87
+ * @returns {void}
88
+ */
89
+ build(options, compilation, resolver, fs, callback) {
90
+ this.buildMeta = {};
91
+ this.buildInfo = {
92
+ cacheable: true
93
+ };
94
+ callback();
95
+ }
96
+
97
+ /**
98
+ * @param {CodeGenerationContext} context context for code generation
99
+ * @returns {CodeGenerationResult} result
100
+ */
101
+ codeGeneration(context) {
102
+ if (this.url === undefined) this.url = this.urlBuffer.toString();
103
+ const sources = new Map();
104
+ sources.set(
105
+ "javascript",
106
+ new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
107
+ );
108
+ const data = new Map();
109
+ data.set("url", this.urlBuffer);
110
+ const runtimeRequirements = new Set();
111
+ runtimeRequirements.add(RuntimeGlobals.module);
112
+ return { sources, runtimeRequirements, data };
113
+ }
114
+
115
+ /**
116
+ * @param {Hash} hash the hash used to track dependencies
117
+ * @param {UpdateHashContext} context context
118
+ * @returns {void}
119
+ */
120
+ updateHash(hash, context) {
121
+ hash.update(this.urlBuffer);
122
+ super.updateHash(hash, context);
123
+ }
124
+
125
+ serialize(context) {
126
+ const { write } = context;
127
+
128
+ write(this.urlBuffer);
129
+ write(this.identifierStr);
130
+ write(this.readableIdentifierStr);
131
+
132
+ super.serialize(context);
133
+ }
134
+
135
+ deserialize(context) {
136
+ const { read } = context;
137
+
138
+ this.urlBuffer = read();
139
+ this.identifierStr = read();
140
+ this.readableIdentifierStr = read();
141
+
142
+ super.deserialize(context);
143
+ }
144
+ }
145
+
146
+ makeSerializable(RawDataUrlModule, "webpack/lib/asset/RawDataUrlModule");
147
+
148
+ module.exports = RawDataUrlModule;
@@ -30,8 +30,8 @@ class AwaitDependenciesInitFragment extends InitFragment {
30
30
  }
31
31
 
32
32
  merge(other) {
33
- const promises = new Set(this.promises);
34
- for (const p of other.promises) {
33
+ const promises = new Set(other.promises);
34
+ for (const p of this.promises) {
35
35
  promises.add(p);
36
36
  }
37
37
  return new AwaitDependenciesInitFragment(promises);
@@ -51,7 +51,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
51
51
  for (const p of promises) {
52
52
  return Template.asString([
53
53
  `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${p}]);`,
54
- `${p} = (__webpack_async_dependencies__.then ? await __webpack_async_dependencies__ : __webpack_async_dependencies__)[0];`,
54
+ `${p} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];`,
55
55
  ""
56
56
  ]);
57
57
  }
@@ -60,7 +60,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
60
60
  // TODO check if destructuring is supported
61
61
  return Template.asString([
62
62
  `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${sepPromises}]);`,
63
- `([${sepPromises}] = __webpack_async_dependencies__.then ? await __webpack_async_dependencies__ : __webpack_async_dependencies__);`,
63
+ `([${sepPromises}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);`,
64
64
  ""
65
65
  ]);
66
66
  }
@@ -50,6 +50,8 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
50
50
  * @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
51
51
  * @property {number} preOrderIndex next pre order index
52
52
  * @property {number} postOrderIndex next post order index
53
+ * @property {boolean} chunkLoading has a chunk loading mechanism
54
+ * @property {boolean} asyncChunks create async chunks
53
55
  */
54
56
 
55
57
  /**
@@ -304,7 +306,15 @@ const visitModules = (
304
306
  availableSources: undefined,
305
307
  availableChildren: undefined,
306
308
  preOrderIndex: 0,
307
- postOrderIndex: 0
309
+ postOrderIndex: 0,
310
+ chunkLoading:
311
+ chunkGroup.options.chunkLoading !== undefined
312
+ ? chunkGroup.options.chunkLoading !== false
313
+ : compilation.outputOptions.chunkLoading !== false,
314
+ asyncChunks:
315
+ chunkGroup.options.asyncChunks !== undefined
316
+ ? chunkGroup.options.asyncChunks
317
+ : compilation.outputOptions.asyncChunks !== false
308
318
  };
309
319
  chunkGroup.index = nextChunkGroupIndex++;
310
320
  if (chunkGroup.getNumberOfParents() > 0) {
@@ -418,7 +428,15 @@ const visitModules = (
418
428
  availableSources: undefined,
419
429
  availableChildren: undefined,
420
430
  preOrderIndex: 0,
421
- postOrderIndex: 0
431
+ postOrderIndex: 0,
432
+ chunkLoading:
433
+ entryOptions.chunkLoading !== undefined
434
+ ? entryOptions.chunkLoading !== false
435
+ : chunkGroupInfo.chunkLoading,
436
+ asyncChunks:
437
+ entryOptions.asyncChunks !== undefined
438
+ ? entryOptions.asyncChunks
439
+ : chunkGroupInfo.asyncChunks
422
440
  };
423
441
  chunkGroupInfoMap.set(entrypoint, cgi);
424
442
 
@@ -442,8 +460,18 @@ const visitModules = (
442
460
  chunkGroup: entrypoint,
443
461
  chunkGroupInfo: cgi
444
462
  });
463
+ } else if (!chunkGroupInfo.asyncChunks || !chunkGroupInfo.chunkLoading) {
464
+ // Just queue the block into the current chunk group
465
+ queue.push({
466
+ action: PROCESS_BLOCK,
467
+ block: b,
468
+ module: module,
469
+ chunk,
470
+ chunkGroup,
471
+ chunkGroupInfo
472
+ });
445
473
  } else {
446
- cgi = namedChunkGroups.get(chunkName);
474
+ cgi = chunkName && namedChunkGroups.get(chunkName);
447
475
  if (!cgi) {
448
476
  c = compilation.addChunkInGroup(
449
477
  b.groupOptions || b.chunkName,
@@ -464,7 +492,9 @@ const visitModules = (
464
492
  availableSources: undefined,
465
493
  availableChildren: undefined,
466
494
  preOrderIndex: 0,
467
- postOrderIndex: 0
495
+ postOrderIndex: 0,
496
+ chunkLoading: chunkGroupInfo.chunkLoading,
497
+ asyncChunks: chunkGroupInfo.asyncChunks
468
498
  };
469
499
  allCreatedChunkGroups.add(c);
470
500
  chunkGroupInfoMap.set(c, cgi);
@@ -518,7 +548,7 @@ const visitModules = (
518
548
  chunkGroup: c,
519
549
  chunkGroupInfo: cgi
520
550
  });
521
- } else {
551
+ } else if (entrypoint !== undefined) {
522
552
  chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
523
553
  }
524
554
  };
@@ -875,7 +905,7 @@ const visitModules = (
875
905
  const module = it.value;
876
906
  if (
877
907
  availableModules.has(module) ||
878
- availableModules.plus.has(m)
908
+ availableModules.plus.has(module)
879
909
  ) {
880
910
  cachedMinAvailableModules.add(module);
881
911
  }
@@ -782,7 +782,7 @@ class PackContent {
782
782
  this.logger.time(timeMessage);
783
783
  }
784
784
  const value = this.lazy();
785
- if (value instanceof Promise) {
785
+ if ("then" in value) {
786
786
  return value.then(data => {
787
787
  const map = data.map;
788
788
  if (timeMessage) {
@@ -830,7 +830,7 @@ class PackContent {
830
830
  this.logger.time(timeMessage);
831
831
  }
832
832
  const value = this.lazy();
833
- if (value instanceof Promise) {
833
+ if ("then" in value) {
834
834
  return value.then(data => {
835
835
  if (timeMessage) {
836
836
  this.logger.timeEnd(timeMessage);
@@ -918,7 +918,7 @@ class PackContent {
918
918
  }
919
919
  const value = this.lazy();
920
920
  this.outdated = false;
921
- if (value instanceof Promise) {
921
+ if ("then" in value) {
922
922
  // Move to state B1
923
923
  this.lazy = write(() =>
924
924
  value.then(data => {
@@ -991,7 +991,10 @@ class PackFileCacheStrategy {
991
991
  allowCollectingMemory,
992
992
  compression
993
993
  }) {
994
- this.fileSerializer = createFileSerializer(fs);
994
+ this.fileSerializer = createFileSerializer(
995
+ fs,
996
+ compiler.options.output.hashFunction
997
+ );
995
998
  this.fileSystemInfo = new FileSystemInfo(fs, {
996
999
  managedPaths: snapshot.managedPaths,
997
1000
  immutablePaths: snapshot.immutablePaths,