webpack 5.69.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 (73) hide show
  1. package/hot/poll.js +1 -1
  2. package/hot/signal.js +1 -1
  3. package/lib/BannerPlugin.js +10 -4
  4. package/lib/Chunk.js +1 -1
  5. package/lib/ChunkGroup.js +1 -1
  6. package/lib/CleanPlugin.js +64 -18
  7. package/lib/Compilation.js +51 -25
  8. package/lib/Compiler.js +16 -3
  9. package/lib/ConstPlugin.js +2 -2
  10. package/lib/ContextModule.js +54 -22
  11. package/lib/ContextModuleFactory.js +13 -12
  12. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  13. package/lib/Dependency.js +7 -0
  14. package/lib/EntryOptionPlugin.js +1 -0
  15. package/lib/ErrorHelpers.js +2 -2
  16. package/lib/ExternalModuleFactoryPlugin.js +4 -4
  17. package/lib/FileSystemInfo.js +8 -0
  18. package/lib/Generator.js +1 -0
  19. package/lib/LoaderOptionsPlugin.js +1 -1
  20. package/lib/Module.js +2 -0
  21. package/lib/ModuleFilenameHelpers.js +3 -3
  22. package/lib/ModuleHashingError.js +29 -0
  23. package/lib/NodeStuffPlugin.js +10 -0
  24. package/lib/NormalModule.js +23 -18
  25. package/lib/NormalModuleFactory.js +17 -10
  26. package/lib/ProgressPlugin.js +3 -4
  27. package/lib/RuntimePlugin.js +18 -0
  28. package/lib/RuntimeTemplate.js +1 -0
  29. package/lib/WebpackOptionsApply.js +2 -0
  30. package/lib/asset/AssetGenerator.js +119 -31
  31. package/lib/cache/ResolverCachePlugin.js +15 -6
  32. package/lib/config/browserslistTargetHandler.js +3 -5
  33. package/lib/config/defaults.js +9 -1
  34. package/lib/config/normalization.js +1 -0
  35. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  36. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  37. package/lib/dependencies/ContextElementDependency.js +33 -1
  38. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  39. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  40. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  41. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +127 -43
  42. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -8
  43. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  44. package/lib/dependencies/ImportContextDependency.js +0 -2
  45. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  46. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  47. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  48. package/lib/dependencies/LoaderPlugin.js +2 -0
  49. package/lib/dependencies/RequireContextDependency.js +0 -16
  50. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  51. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
  52. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  53. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  54. package/lib/ids/HashedModuleIdsPlugin.js +2 -2
  55. package/lib/ids/IdHelpers.js +1 -1
  56. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  57. package/lib/javascript/JavascriptParser.js +66 -40
  58. package/lib/library/UmdLibraryPlugin.js +5 -3
  59. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
  60. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
  61. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  62. package/lib/schemes/HttpUriPlugin.js +44 -3
  63. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  64. package/lib/util/internalSerializables.js +4 -0
  65. package/lib/web/JsonpChunkLoadingRuntimeModule.js +17 -6
  66. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
  67. package/module.d.ts +15 -0
  68. package/package.json +2 -2
  69. package/schemas/WebpackOptions.check.js +1 -1
  70. package/schemas/WebpackOptions.json +17 -1
  71. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  72. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  73. package/types.d.ts +179 -83
@@ -128,7 +128,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
128
128
  loadersPrefix = "";
129
129
  const idx = request.lastIndexOf("!");
130
130
  if (idx >= 0) {
131
- let loadersRequest = request.substr(0, idx + 1);
131
+ let loadersRequest = request.slice(0, idx + 1);
132
132
  let i;
133
133
  for (
134
134
  i = 0;
@@ -138,7 +138,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
138
138
  loadersPrefix += "!";
139
139
  }
140
140
  loadersRequest = loadersRequest
141
- .substr(i)
141
+ .slice(i)
142
142
  .replace(/!+$/, "")
143
143
  .replace(/!!+/g, "!");
144
144
  if (loadersRequest === "") {
@@ -146,7 +146,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
146
146
  } else {
147
147
  loaders = loadersRequest.split("!");
148
148
  }
149
- resource = request.substr(idx + 1);
149
+ resource = request.slice(idx + 1);
150
150
  } else {
151
151
  loaders = [];
152
152
  resource = request;
@@ -217,7 +217,12 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
217
217
  contextDependencies
218
218
  });
219
219
  }
220
- const [contextResult, loaderResult] = result;
220
+ let [contextResult, loaderResult] = result;
221
+ if (contextResult.length > 1) {
222
+ const first = contextResult[0];
223
+ contextResult = contextResult.filter(r => r.path);
224
+ if (contextResult.length === 0) contextResult.push(first);
225
+ }
221
226
  this.hooks.afterResolve.callAsync(
222
227
  {
223
228
  addon:
@@ -287,7 +292,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
287
292
  } = options;
288
293
  if (!regExp || !resource) return callback(null, []);
289
294
 
290
- let severalContexts = false;
291
295
  const addDirectoryChecked = (ctx, directory, visited, callback) => {
292
296
  fs.realpath(directory, (err, realPath) => {
293
297
  if (err) return callback(err);
@@ -343,7 +347,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
343
347
  const obj = {
344
348
  context: ctx,
345
349
  request:
346
- "." + subResource.substr(ctx.length).replace(/\\/g, "/")
350
+ "." + subResource.slice(ctx.length).replace(/\\/g, "/")
347
351
  };
348
352
 
349
353
  this.hooks.alternativeRequests.callAsync(
@@ -354,15 +358,13 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
354
358
  alternatives = alternatives
355
359
  .filter(obj => regExp.test(obj.request))
356
360
  .map(obj => {
357
- const request = severalContexts
358
- ? join(fs, obj.context, obj.request)
359
- : obj.request;
360
361
  const dep = new ContextElementDependency(
361
- request + resourceQuery + resourceFragment,
362
+ `${obj.request}${resourceQuery}${resourceFragment}`,
362
363
  obj.request,
363
364
  typePrefix,
364
365
  category,
365
- referencedExports
366
+ referencedExports,
367
+ obj.context
366
368
  );
367
369
  dep.optional = true;
368
370
  return dep;
@@ -409,7 +411,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
409
411
  if (typeof resource === "string") {
410
412
  visitResource(resource, callback);
411
413
  } else {
412
- severalContexts = true;
413
414
  asyncLib.map(resource, visitResource, (err, result) => {
414
415
  if (err) return callback(err);
415
416
 
@@ -29,7 +29,7 @@ class DelegatedModuleFactoryPlugin {
29
29
  const [dependency] = data.dependencies;
30
30
  const { request } = dependency;
31
31
  if (request && request.startsWith(`${scope}/`)) {
32
- const innerRequest = "." + request.substr(scope.length);
32
+ const innerRequest = "." + request.slice(scope.length);
33
33
  let resolved;
34
34
  if (innerRequest in this.options.content) {
35
35
  resolved = this.options.content[innerRequest];
package/lib/Dependency.js CHANGED
@@ -182,6 +182,13 @@ class Dependency {
182
182
  this._loc = undefined;
183
183
  }
184
184
 
185
+ /**
186
+ * @returns {string | undefined} a request context
187
+ */
188
+ getContext() {
189
+ return undefined;
190
+ }
191
+
185
192
  /**
186
193
  * @returns {string | null} an identifier to merge equal requests
187
194
  */
@@ -62,6 +62,7 @@ class EntryOptionPlugin {
62
62
  runtime: desc.runtime,
63
63
  layer: desc.layer,
64
64
  dependOn: desc.dependOn,
65
+ baseUri: desc.baseUri,
65
66
  publicPath: desc.publicPath,
66
67
  chunkLoading: desc.chunkLoading,
67
68
  asyncChunks: desc.asyncChunks,
@@ -43,8 +43,8 @@ exports.cutOffMessage = (stack, message) => {
43
43
  if (nextLine === -1) {
44
44
  return stack === message ? "" : stack;
45
45
  } else {
46
- const firstLine = stack.substr(0, nextLine);
47
- return firstLine === message ? stack.substr(nextLine + 1) : stack;
46
+ const firstLine = stack.slice(0, nextLine);
47
+ return firstLine === message ? stack.slice(nextLine + 1) : stack;
48
48
  }
49
49
  };
50
50
 
@@ -89,8 +89,8 @@ class ExternalModuleFactoryPlugin {
89
89
  UNSPECIFIED_EXTERNAL_TYPE_REGEXP.test(externalConfig)
90
90
  ) {
91
91
  const idx = externalConfig.indexOf(" ");
92
- type = externalConfig.substr(0, idx);
93
- externalConfig = externalConfig.substr(idx + 1);
92
+ type = externalConfig.slice(0, idx);
93
+ externalConfig = externalConfig.slice(idx + 1);
94
94
  } else if (
95
95
  Array.isArray(externalConfig) &&
96
96
  externalConfig.length > 0 &&
@@ -98,9 +98,9 @@ class ExternalModuleFactoryPlugin {
98
98
  ) {
99
99
  const firstItem = externalConfig[0];
100
100
  const idx = firstItem.indexOf(" ");
101
- type = firstItem.substr(0, idx);
101
+ type = firstItem.slice(0, idx);
102
102
  externalConfig = [
103
- firstItem.substr(idx + 1),
103
+ firstItem.slice(idx + 1),
104
104
  ...externalConfig.slice(1)
105
105
  ];
106
106
  }
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { create: createResolver } = require("enhanced-resolve");
9
+ const nodeModule = require("module");
9
10
  const asyncLib = require("neo-async");
10
11
  const AsyncQueue = require("./util/AsyncQueue");
11
12
  const StackedCacheMap = require("./util/StackedCacheMap");
@@ -22,6 +23,8 @@ const processAsyncTree = require("./util/processAsyncTree");
22
23
 
23
24
  const supportsEsm = +process.versions.modules >= 83;
24
25
 
26
+ const builtinModules = new Set(nodeModule.builtinModules);
27
+
25
28
  let FS_ACCURACY = 2000;
26
29
 
27
30
  const EMPTY_SET = new Set();
@@ -1673,6 +1676,11 @@ class FileSystemInfo {
1673
1676
  // e.g. import.meta
1674
1677
  continue;
1675
1678
  }
1679
+
1680
+ // we should not track Node.js build dependencies
1681
+ if (dependency.startsWith("node:")) continue;
1682
+ if (builtinModules.has(dependency)) continue;
1683
+
1676
1684
  push({
1677
1685
  type: RBDT_RESOLVE_ESM_FILE,
1678
1686
  context,
package/lib/Generator.js CHANGED
@@ -38,6 +38,7 @@
38
38
  * @property {NormalModule} module the module
39
39
  * @property {ChunkGraph} chunkGraph
40
40
  * @property {RuntimeSpec} runtime
41
+ * @property {RuntimeTemplate=} runtimeTemplate
41
42
  */
42
43
 
43
44
  /**
@@ -52,7 +52,7 @@ class LoaderOptionsPlugin {
52
52
  if (
53
53
  ModuleFilenameHelpers.matchObject(
54
54
  options,
55
- i < 0 ? resource : resource.substr(0, i)
55
+ i < 0 ? resource : resource.slice(0, i)
56
56
  )
57
57
  ) {
58
58
  for (const key of Object.keys(options)) {
package/lib/Module.js CHANGED
@@ -49,6 +49,7 @@ const makeSerializable = require("./util/makeSerializable");
49
49
  * @property {string=} type the type of source that should be generated
50
50
  */
51
51
 
52
+ // TODO webpack 6: compilation will be required in CodeGenerationContext
52
53
  /**
53
54
  * @typedef {Object} CodeGenerationContext
54
55
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -58,6 +59,7 @@ const makeSerializable = require("./util/makeSerializable");
58
59
  * @property {RuntimeSpec} runtime the runtimes code should be generated for
59
60
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
60
61
  * @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
62
+ * @property {Compilation=} compilation the compilation
61
63
  */
62
64
 
63
65
  /**
@@ -47,7 +47,7 @@ const getAfter = (strFn, token) => {
47
47
  return () => {
48
48
  const str = strFn();
49
49
  const idx = str.indexOf(token);
50
- return idx < 0 ? "" : str.substr(idx);
50
+ return idx < 0 ? "" : str.slice(idx);
51
51
  };
52
52
  };
53
53
 
@@ -55,7 +55,7 @@ const getBefore = (strFn, token) => {
55
55
  return () => {
56
56
  const str = strFn();
57
57
  const idx = str.lastIndexOf(token);
58
- return idx < 0 ? "" : str.substr(0, idx);
58
+ return idx < 0 ? "" : str.slice(0, idx);
59
59
  };
60
60
  };
61
61
 
@@ -64,7 +64,7 @@ const getHash = (strFn, hashFunction) => {
64
64
  const hash = createHash(hashFunction);
65
65
  hash.update(strFn());
66
66
  const digest = /** @type {string} */ (hash.digest("hex"));
67
- return digest.substr(0, 4);
67
+ return digest.slice(0, 4);
68
68
  };
69
69
  };
70
70
 
@@ -0,0 +1,29 @@
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 WebpackError = require("./WebpackError");
9
+
10
+ /** @typedef {import("./Module")} Module */
11
+
12
+ class ModuleHashingError extends WebpackError {
13
+ /**
14
+ * Create a new ModuleHashingError
15
+ * @param {Module} module related module
16
+ * @param {Error} error Original error
17
+ */
18
+ constructor(module, error) {
19
+ super();
20
+
21
+ this.name = "ModuleHashingError";
22
+ this.error = error;
23
+ this.message = error.message;
24
+ this.details = error.stack;
25
+ this.module = module;
26
+ }
27
+ }
28
+
29
+ module.exports = ModuleHashingError;
@@ -69,6 +69,16 @@ class NodeStuffPlugin {
69
69
  );
70
70
  }
71
71
  });
72
+ parser.hooks.rename.for("global").tap("NodeStuffPlugin", expr => {
73
+ const dep = new ConstDependency(
74
+ RuntimeGlobals.global,
75
+ expr.range,
76
+ [RuntimeGlobals.global]
77
+ );
78
+ dep.loc = expr.loc;
79
+ parser.state.module.addPresentationalDependency(dep);
80
+ return false;
81
+ });
72
82
  }
73
83
 
74
84
  const setModuleConstant = (expressionName, fn, warning) => {
@@ -50,6 +50,7 @@ const memoize = require("./util/memoize");
50
50
  /** @typedef {import("webpack-sources").Source} Source */
51
51
  /** @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext} NormalModuleLoaderContext */
52
52
  /** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
53
+ /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
53
54
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
54
55
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
55
56
  /** @typedef {import("./Compiler")} Compiler */
@@ -194,6 +195,25 @@ makeSerializable(
194
195
  * @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
195
196
  */
196
197
 
198
+ /**
199
+ * @typedef {Object} NormalModuleCreateData
200
+ * @property {string=} layer an optional layer in which the module is
201
+ * @property {string} type module type
202
+ * @property {string} request request string
203
+ * @property {string} userRequest request intended by user (without loaders from config)
204
+ * @property {string} rawRequest request without resolving
205
+ * @property {LoaderItem[]} loaders list of loaders
206
+ * @property {string} resource path + query of the real resource
207
+ * @property {Record<string, any>=} resourceResolveData resource resolve data
208
+ * @property {string} context context directory for resolving
209
+ * @property {string=} matchResource path + query of the matched resource (virtual)
210
+ * @property {Parser} parser the parser used
211
+ * @property {Record<string, any>=} parserOptions the options of the parser used
212
+ * @property {Generator} generator the generator used
213
+ * @property {Record<string, any>=} generatorOptions the options of the generator used
214
+ * @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
215
+ */
216
+
197
217
  /** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
198
218
  const compilationHooksMap = new WeakMap();
199
219
 
@@ -246,22 +266,7 @@ class NormalModule extends Module {
246
266
  }
247
267
 
248
268
  /**
249
- * @param {Object} options options object
250
- * @param {string=} options.layer an optional layer in which the module is
251
- * @param {string} options.type module type
252
- * @param {string} options.request request string
253
- * @param {string} options.userRequest request intended by user (without loaders from config)
254
- * @param {string} options.rawRequest request without resolving
255
- * @param {LoaderItem[]} options.loaders list of loaders
256
- * @param {string} options.resource path + query of the real resource
257
- * @param {Record<string, any>=} options.resourceResolveData resource resolve data
258
- * @param {string} options.context context directory for resolving
259
- * @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
260
- * @param {Parser} options.parser the parser used
261
- * @param {object} options.parserOptions the options of the parser used
262
- * @param {Generator} options.generator the generator used
263
- * @param {object} options.generatorOptions the options of the generator used
264
- * @param {Object} options.resolveOptions options used for resolving requests from this module
269
+ * @param {NormalModuleCreateData} options options object
265
270
  */
266
271
  constructor({
267
272
  layer,
@@ -370,7 +375,7 @@ class NormalModule extends Module {
370
375
  nameForCondition() {
371
376
  const resource = this.matchResource || this.resource;
372
377
  const idx = resource.indexOf("?");
373
- if (idx >= 0) return resource.substr(0, idx);
378
+ if (idx >= 0) return resource.slice(0, idx);
374
379
  return resource;
375
380
  }
376
381
 
@@ -553,7 +558,7 @@ class NormalModule extends Module {
553
558
  let { options } = loader;
554
559
 
555
560
  if (typeof options === "string") {
556
- if (options.substr(0, 1) === "{" && options.substr(-1) === "}") {
561
+ if (options.startsWith("{") && options.endsWith("}")) {
557
562
  try {
558
563
  options = parseJson(options);
559
564
  } catch (e) {
@@ -34,14 +34,19 @@ const {
34
34
  } = require("./util/identifier");
35
35
 
36
36
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
37
+ /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
37
38
  /** @typedef {import("./Generator")} Generator */
38
39
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
39
40
  /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
41
+ /** @typedef {import("./NormalModule").NormalModuleCreateData} NormalModuleCreateData */
40
42
  /** @typedef {import("./Parser")} Parser */
41
43
  /** @typedef {import("./ResolverFactory")} ResolverFactory */
42
44
  /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
43
45
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
44
46
 
47
+ /** @typedef {Pick<RuleSetRule, 'type'|'sideEffects'|'parser'|'generator'|'resolve'|'layer'>} ModuleSettings */
48
+ /** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
49
+
45
50
  /**
46
51
  * @typedef {Object} ResolveData
47
52
  * @property {ModuleFactoryCreateData["contextInfo"]} contextInfo
@@ -51,7 +56,7 @@ const {
51
56
  * @property {Record<string, any> | undefined} assertions
52
57
  * @property {ModuleDependency[]} dependencies
53
58
  * @property {string} dependencyType
54
- * @property {Object} createData
59
+ * @property {CreateData} createData
55
60
  * @property {LazySet<string>} fileDependencies
56
61
  * @property {LazySet<string>} missingDependencies
57
62
  * @property {LazySet<string>} contextDependencies
@@ -199,7 +204,7 @@ class NormalModuleFactory extends ModuleFactory {
199
204
  }) {
200
205
  super();
201
206
  this.hooks = Object.freeze({
202
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
207
+ /** @type {AsyncSeriesBailHook<[ResolveData], Module | false | void>} */
203
208
  resolve: new AsyncSeriesBailHook(["resolveData"]),
204
209
  /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
205
210
  resolveForScheme: new HookMap(
@@ -209,15 +214,15 @@ class NormalModuleFactory extends ModuleFactory {
209
214
  resolveInScheme: new HookMap(
210
215
  () => new AsyncSeriesBailHook(["resourceData", "resolveData"])
211
216
  ),
212
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
217
+ /** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
213
218
  factorize: new AsyncSeriesBailHook(["resolveData"]),
214
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
219
+ /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
215
220
  beforeResolve: new AsyncSeriesBailHook(["resolveData"]),
216
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
221
+ /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
217
222
  afterResolve: new AsyncSeriesBailHook(["resolveData"]),
218
- /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], TODO>} */
223
+ /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
219
224
  createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
220
- /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], TODO>} */
225
+ /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
221
226
  module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
222
227
  createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
223
228
  parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
@@ -301,7 +306,9 @@ class NormalModuleFactory extends ModuleFactory {
301
306
  return callback(new Error("Empty dependency (no request)"));
302
307
  }
303
308
 
304
- createdModule = new NormalModule(createData);
309
+ createdModule = new NormalModule(
310
+ /** @type {NormalModuleCreateData} */ (createData)
311
+ );
305
312
  }
306
313
 
307
314
  createdModule = this.hooks.module.call(
@@ -372,7 +379,7 @@ class NormalModuleFactory extends ModuleFactory {
372
379
  resource: matchResource,
373
380
  ...cacheParseResource(matchResource)
374
381
  };
375
- requestWithoutMatchResource = request.substr(
382
+ requestWithoutMatchResource = request.slice(
376
383
  matchResourceMatch[0].length
377
384
  );
378
385
  }
@@ -430,7 +437,7 @@ class NormalModuleFactory extends ModuleFactory {
430
437
  try {
431
438
  for (const item of loaders) {
432
439
  if (typeof item.options === "string" && item.options[0] === "?") {
433
- const ident = item.options.substr(1);
440
+ const ident = item.options.slice(1);
434
441
  if (ident === "[[missing ident]]") {
435
442
  throw new Error(
436
443
  "No ident is provided by referenced loader. " +
@@ -531,15 +531,14 @@ class ProgressPlugin {
531
531
  }
532
532
  });
533
533
  interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
534
- compiler.hooks.initialize.intercept({
534
+ compiler.hooks.beforeRun.intercept({
535
535
  name: "ProgressPlugin",
536
536
  call() {
537
537
  handler(0, "");
538
538
  }
539
539
  });
540
- interceptHook(compiler.hooks.initialize, 0.01, "setup", "initialize");
541
- interceptHook(compiler.hooks.beforeRun, 0.02, "setup", "before run");
542
- interceptHook(compiler.hooks.run, 0.03, "setup", "run");
540
+ interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
541
+ interceptHook(compiler.hooks.run, 0.02, "setup", "run");
543
542
  interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
544
543
  interceptHook(
545
544
  compiler.hooks.normalModuleFactory,
@@ -11,6 +11,7 @@ const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirement
11
11
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
12
12
  const AsyncModuleRuntimeModule = require("./runtime/AsyncModuleRuntimeModule");
13
13
  const AutoPublicPathRuntimeModule = require("./runtime/AutoPublicPathRuntimeModule");
14
+ const BaseUriRuntimeModule = require("./runtime/BaseUriRuntimeModule");
14
15
  const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
15
16
  const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
16
17
  const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
@@ -96,6 +97,15 @@ class RuntimePlugin {
96
97
  */
97
98
  apply(compiler) {
98
99
  compiler.hooks.compilation.tap("RuntimePlugin", compilation => {
100
+ const globalChunkLoading = compilation.outputOptions.chunkLoading;
101
+ const isChunkLoadingDisabledForChunk = chunk => {
102
+ const options = chunk.getEntryOptions();
103
+ const chunkLoading =
104
+ options && options.chunkLoading !== undefined
105
+ ? options.chunkLoading
106
+ : globalChunkLoading;
107
+ return chunkLoading === false;
108
+ };
99
109
  compilation.dependencyTemplates.set(
100
110
  RuntimeRequirementsDependency,
101
111
  new RuntimeRequirementsDependency.Template()
@@ -413,6 +423,14 @@ class RuntimePlugin {
413
423
  );
414
424
  return true;
415
425
  });
426
+ compilation.hooks.runtimeRequirementInTree
427
+ .for(RuntimeGlobals.baseURI)
428
+ .tap("RuntimePlugin", chunk => {
429
+ if (isChunkLoadingDisabledForChunk(chunk)) {
430
+ compilation.addRuntimeModule(chunk, new BaseUriRuntimeModule());
431
+ return true;
432
+ }
433
+ });
416
434
  // TODO webpack 6: remove CompatRuntimeModule
417
435
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
418
436
  "RuntimePlugin",
@@ -83,6 +83,7 @@ class RuntimeTemplate {
83
83
  this.outputOptions = outputOptions || {};
84
84
  this.requestShortener = requestShortener;
85
85
  this.globalObject = getGlobalObject(outputOptions.globalObject);
86
+ this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
86
87
  }
87
88
 
88
89
  isIIFE() {
@@ -35,6 +35,7 @@ const ResolverCachePlugin = require("./cache/ResolverCachePlugin");
35
35
 
36
36
  const CommonJsPlugin = require("./dependencies/CommonJsPlugin");
37
37
  const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin");
38
+ const ImportMetaContextPlugin = require("./dependencies/ImportMetaContextPlugin");
38
39
  const ImportMetaPlugin = require("./dependencies/ImportMetaPlugin");
39
40
  const ImportPlugin = require("./dependencies/ImportPlugin");
40
41
  const LoaderPlugin = require("./dependencies/LoaderPlugin");
@@ -361,6 +362,7 @@ class WebpackOptionsApply extends OptionsApply {
361
362
  new RequireEnsurePlugin().apply(compiler);
362
363
  new RequireContextPlugin().apply(compiler);
363
364
  new ImportPlugin().apply(compiler);
365
+ new ImportMetaContextPlugin().apply(compiler);
364
366
  new SystemPlugin().apply(compiler);
365
367
  new ImportMetaPlugin().apply(compiler);
366
368
  new URLPlugin().apply(compiler);