webpack 5.77.0 → 5.78.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 (66) hide show
  1. package/bin/webpack.js +0 -0
  2. package/lib/APIPlugin.js +25 -18
  3. package/lib/CompatibilityPlugin.js +53 -52
  4. package/lib/ConstPlugin.js +22 -15
  5. package/lib/ContextModule.js +3 -2
  6. package/lib/DefinePlugin.js +44 -36
  7. package/lib/DelegatedModule.js +2 -1
  8. package/lib/DllModule.js +2 -1
  9. package/lib/ErrorHelpers.js +61 -22
  10. package/lib/ExportsInfoApiPlugin.js +16 -9
  11. package/lib/ExternalModule.js +2 -1
  12. package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
  13. package/lib/FlagDependencyExportsPlugin.js +336 -348
  14. package/lib/FlagDependencyUsagePlugin.js +6 -8
  15. package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
  16. package/lib/HotModuleReplacementPlugin.js +50 -45
  17. package/lib/JavascriptMetaInfoPlugin.js +16 -9
  18. package/lib/ModuleTypeConstants.js +50 -0
  19. package/lib/NodeStuffPlugin.js +35 -31
  20. package/lib/NormalModule.js +2 -1
  21. package/lib/NormalModuleFactory.js +7 -1
  22. package/lib/ProvidePlugin.js +17 -10
  23. package/lib/RawModule.js +2 -1
  24. package/lib/RequireJsStuffPlugin.js +15 -15
  25. package/lib/UseStrictPlugin.js +15 -8
  26. package/lib/WebpackIsIncludedPlugin.js +16 -9
  27. package/lib/config/defaults.js +16 -8
  28. package/lib/config/normalization.js +4 -0
  29. package/lib/container/ContainerEntryModule.js +2 -1
  30. package/lib/css/CssParser.js +22 -2
  31. package/lib/debug/ProfilingPlugin.js +20 -12
  32. package/lib/dependencies/AMDPlugin.js +26 -20
  33. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
  34. package/lib/dependencies/CommonJsPlugin.js +29 -25
  35. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  36. package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
  37. package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
  38. package/lib/dependencies/ImportMetaPlugin.js +26 -20
  39. package/lib/dependencies/ImportPlugin.js +14 -7
  40. package/lib/dependencies/RequireContextPlugin.js +12 -6
  41. package/lib/dependencies/RequireEnsurePlugin.js +13 -7
  42. package/lib/dependencies/RequireIncludePlugin.js +11 -5
  43. package/lib/dependencies/SystemPlugin.js +21 -15
  44. package/lib/dependencies/URLPlugin.js +15 -9
  45. package/lib/dependencies/WorkerPlugin.js +14 -8
  46. package/lib/javascript/JavascriptModulesPlugin.js +157 -164
  47. package/lib/json/JsonModulesPlugin.js +13 -5
  48. package/lib/library/AmdLibraryPlugin.js +22 -6
  49. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  50. package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
  51. package/lib/optimize/ConcatenatedModule.js +2 -1
  52. package/lib/optimize/InnerGraphPlugin.js +47 -46
  53. package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
  54. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  55. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
  56. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
  57. package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
  58. package/lib/web/FetchCompileWasmPlugin.js +40 -40
  59. package/package.json +1 -1
  60. package/schemas/WebpackOptions.check.js +1 -1
  61. package/schemas/WebpackOptions.json +18 -0
  62. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  63. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  64. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  65. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  66. package/types.d.ts +10 -0
@@ -5,6 +5,10 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC
11
+ } = require("../ModuleTypeConstants");
8
12
  const RuntimeGlobals = require("../RuntimeGlobals");
9
13
  const WebpackError = require("../WebpackError");
10
14
  const {
@@ -18,6 +22,8 @@ const SystemRuntimeModule = require("./SystemRuntimeModule");
18
22
 
19
23
  /** @typedef {import("../Compiler")} Compiler */
20
24
 
25
+ const PLUGIN_NAME = "SystemPlugin";
26
+
21
27
  class SystemPlugin {
22
28
  /**
23
29
  * Apply the plugin
@@ -26,17 +32,17 @@ class SystemPlugin {
26
32
  */
27
33
  apply(compiler) {
28
34
  compiler.hooks.compilation.tap(
29
- "SystemPlugin",
35
+ PLUGIN_NAME,
30
36
  (compilation, { normalModuleFactory }) => {
31
37
  compilation.hooks.runtimeRequirementInModule
32
38
  .for(RuntimeGlobals.system)
33
- .tap("SystemPlugin", (module, set) => {
39
+ .tap(PLUGIN_NAME, (module, set) => {
34
40
  set.add(RuntimeGlobals.requireScope);
35
41
  });
36
42
 
37
43
  compilation.hooks.runtimeRequirementInTree
38
44
  .for(RuntimeGlobals.system)
39
- .tap("SystemPlugin", (chunk, set) => {
45
+ .tap(PLUGIN_NAME, (chunk, set) => {
40
46
  compilation.addRuntimeModule(chunk, new SystemRuntimeModule());
41
47
  });
42
48
 
@@ -48,11 +54,11 @@ class SystemPlugin {
48
54
  const setNotSupported = name => {
49
55
  parser.hooks.evaluateTypeof
50
56
  .for(name)
51
- .tap("SystemPlugin", evaluateToString("undefined"));
57
+ .tap(PLUGIN_NAME, evaluateToString("undefined"));
52
58
  parser.hooks.expression
53
59
  .for(name)
54
60
  .tap(
55
- "SystemPlugin",
61
+ PLUGIN_NAME,
56
62
  expressionIsUnsupported(
57
63
  parser,
58
64
  name + " is not supported by webpack."
@@ -63,27 +69,27 @@ class SystemPlugin {
63
69
  parser.hooks.typeof
64
70
  .for("System.import")
65
71
  .tap(
66
- "SystemPlugin",
72
+ PLUGIN_NAME,
67
73
  toConstantDependency(parser, JSON.stringify("function"))
68
74
  );
69
75
  parser.hooks.evaluateTypeof
70
76
  .for("System.import")
71
- .tap("SystemPlugin", evaluateToString("function"));
77
+ .tap(PLUGIN_NAME, evaluateToString("function"));
72
78
  parser.hooks.typeof
73
79
  .for("System")
74
80
  .tap(
75
- "SystemPlugin",
81
+ PLUGIN_NAME,
76
82
  toConstantDependency(parser, JSON.stringify("object"))
77
83
  );
78
84
  parser.hooks.evaluateTypeof
79
85
  .for("System")
80
- .tap("SystemPlugin", evaluateToString("object"));
86
+ .tap(PLUGIN_NAME, evaluateToString("object"));
81
87
 
82
88
  setNotSupported("System.set");
83
89
  setNotSupported("System.get");
84
90
  setNotSupported("System.register");
85
91
 
86
- parser.hooks.expression.for("System").tap("SystemPlugin", expr => {
92
+ parser.hooks.expression.for("System").tap(PLUGIN_NAME, expr => {
87
93
  const dep = new ConstDependency(RuntimeGlobals.system, expr.range, [
88
94
  RuntimeGlobals.system
89
95
  ]);
@@ -92,7 +98,7 @@ class SystemPlugin {
92
98
  return true;
93
99
  });
94
100
 
95
- parser.hooks.call.for("System.import").tap("SystemPlugin", expr => {
101
+ parser.hooks.call.for("System.import").tap(PLUGIN_NAME, expr => {
96
102
  parser.state.module.addWarning(
97
103
  new SystemImportDeprecationWarning(expr.loc)
98
104
  );
@@ -107,11 +113,11 @@ class SystemPlugin {
107
113
  };
108
114
 
109
115
  normalModuleFactory.hooks.parser
110
- .for("javascript/auto")
111
- .tap("SystemPlugin", handler);
116
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
117
+ .tap(PLUGIN_NAME, handler);
112
118
  normalModuleFactory.hooks.parser
113
- .for("javascript/dynamic")
114
- .tap("SystemPlugin", handler);
119
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
120
+ .tap(PLUGIN_NAME, handler);
115
121
  }
116
122
  );
117
123
  }
@@ -6,6 +6,10 @@
6
6
  "use strict";
7
7
 
8
8
  const { pathToFileURL } = require("url");
9
+ const {
10
+ JAVASCRIPT_MODULE_TYPE_AUTO,
11
+ JAVASCRIPT_MODULE_TYPE_ESM
12
+ } = require("../ModuleTypeConstants");
9
13
  const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
10
14
  const { approve } = require("../javascript/JavascriptParserHelpers");
11
15
  const InnerGraph = require("../optimize/InnerGraph");
@@ -16,13 +20,15 @@ const URLDependency = require("./URLDependency");
16
20
  /** @typedef {import("../NormalModule")} NormalModule */
17
21
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
18
22
 
23
+ const PLUGIN_NAME = "URLPlugin";
24
+
19
25
  class URLPlugin {
20
26
  /**
21
27
  * @param {Compiler} compiler compiler
22
28
  */
23
29
  apply(compiler) {
24
30
  compiler.hooks.compilation.tap(
25
- "URLPlugin",
31
+ PLUGIN_NAME,
26
32
  (compilation, { normalModuleFactory }) => {
27
33
  compilation.dependencyFactories.set(URLDependency, normalModuleFactory);
28
34
  compilation.dependencyTemplates.set(
@@ -76,10 +82,10 @@ class URLPlugin {
76
82
  return request;
77
83
  };
78
84
 
79
- parser.hooks.canRename.for("URL").tap("URLPlugin", approve);
85
+ parser.hooks.canRename.for("URL").tap(PLUGIN_NAME, approve);
80
86
  parser.hooks.evaluateNewExpression
81
87
  .for("URL")
82
- .tap("URLPlugin", expr => {
88
+ .tap(PLUGIN_NAME, expr => {
83
89
  const request = getUrlRequest(expr);
84
90
  if (!request) return;
85
91
  const url = new URL(request, getUrl(parser.state.module));
@@ -88,7 +94,7 @@ class URLPlugin {
88
94
  .setString(url.toString())
89
95
  .setRange(expr.range);
90
96
  });
91
- parser.hooks.new.for("URL").tap("URLPlugin", _expr => {
97
+ parser.hooks.new.for("URL").tap(PLUGIN_NAME, _expr => {
92
98
  const expr = /** @type {NewExpressionNode} */ (_expr);
93
99
 
94
100
  const request = getUrlRequest(expr);
@@ -107,7 +113,7 @@ class URLPlugin {
107
113
  InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
108
114
  return true;
109
115
  });
110
- parser.hooks.isPure.for("NewExpression").tap("URLPlugin", _expr => {
116
+ parser.hooks.isPure.for("NewExpression").tap(PLUGIN_NAME, _expr => {
111
117
  const expr = /** @type {NewExpressionNode} */ (_expr);
112
118
  const { callee } = expr;
113
119
  if (callee.type !== "Identifier") return;
@@ -121,12 +127,12 @@ class URLPlugin {
121
127
  };
122
128
 
123
129
  normalModuleFactory.hooks.parser
124
- .for("javascript/auto")
125
- .tap("URLPlugin", parserCallback);
130
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
131
+ .tap(PLUGIN_NAME, parserCallback);
126
132
 
127
133
  normalModuleFactory.hooks.parser
128
- .for("javascript/esm")
129
- .tap("URLPlugin", parserCallback);
134
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
135
+ .tap(PLUGIN_NAME, parserCallback);
130
136
  }
131
137
  );
132
138
  }
@@ -8,6 +8,10 @@
8
8
  const { pathToFileURL } = require("url");
9
9
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const CommentCompilationWarning = require("../CommentCompilationWarning");
11
+ const {
12
+ JAVASCRIPT_MODULE_TYPE_AUTO,
13
+ JAVASCRIPT_MODULE_TYPE_ESM
14
+ } = require("../ModuleTypeConstants");
11
15
  const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
12
16
  const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
13
17
  const { equals } = require("../util/ArrayHelpers");
@@ -47,6 +51,8 @@ const DEFAULT_SYNTAX = [
47
51
  /** @type {WeakMap<ParserState, number>} */
48
52
  const workerIndexMap = new WeakMap();
49
53
 
54
+ const PLUGIN_NAME = "WorkerPlugin";
55
+
50
56
  class WorkerPlugin {
51
57
  constructor(chunkLoading, wasmLoading, module, workerPublicPath) {
52
58
  this._chunkLoading = chunkLoading;
@@ -71,7 +77,7 @@ class WorkerPlugin {
71
77
  compiler.root
72
78
  );
73
79
  compiler.hooks.thisCompilation.tap(
74
- "WorkerPlugin",
80
+ PLUGIN_NAME,
75
81
  (compilation, { normalModuleFactory }) => {
76
82
  compilation.dependencyFactories.set(
77
83
  WorkerDependency,
@@ -375,7 +381,7 @@ class WorkerPlugin {
375
381
  if (item.endsWith("()")) {
376
382
  parser.hooks.call
377
383
  .for(item.slice(0, -2))
378
- .tap("WorkerPlugin", handleNewWorker);
384
+ .tap(PLUGIN_NAME, handleNewWorker);
379
385
  } else {
380
386
  const match = /^(.+?)(\(\))?\s+from\s+(.+)$/.exec(item);
381
387
  if (match) {
@@ -384,7 +390,7 @@ class WorkerPlugin {
384
390
  const source = match[3];
385
391
  (call ? parser.hooks.call : parser.hooks.new)
386
392
  .for(harmonySpecifierTag)
387
- .tap("WorkerPlugin", expr => {
393
+ .tap(PLUGIN_NAME, expr => {
388
394
  const settings = /** @type {HarmonySettings} */ (
389
395
  parser.currentTagData
390
396
  );
@@ -398,7 +404,7 @@ class WorkerPlugin {
398
404
  return handleNewWorker(expr);
399
405
  });
400
406
  } else {
401
- parser.hooks.new.for(item).tap("WorkerPlugin", handleNewWorker);
407
+ parser.hooks.new.for(item).tap(PLUGIN_NAME, handleNewWorker);
402
408
  }
403
409
  }
404
410
  };
@@ -409,11 +415,11 @@ class WorkerPlugin {
409
415
  }
410
416
  };
411
417
  normalModuleFactory.hooks.parser
412
- .for("javascript/auto")
413
- .tap("WorkerPlugin", parserPlugin);
418
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
419
+ .tap(PLUGIN_NAME, parserPlugin);
414
420
  normalModuleFactory.hooks.parser
415
- .for("javascript/esm")
416
- .tap("WorkerPlugin", parserPlugin);
421
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
422
+ .tap(PLUGIN_NAME, parserPlugin);
417
423
  }
418
424
  );
419
425
  }
@@ -18,6 +18,11 @@ const Compilation = require("../Compilation");
18
18
  const { tryRunOrWebpackError } = require("../HookWebpackError");
19
19
  const HotUpdateChunk = require("../HotUpdateChunk");
20
20
  const InitFragment = require("../InitFragment");
21
+ const {
22
+ JAVASCRIPT_MODULE_TYPE_AUTO,
23
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
24
+ JAVASCRIPT_MODULE_TYPE_ESM
25
+ } = require("../ModuleTypeConstants");
21
26
  const RuntimeGlobals = require("../RuntimeGlobals");
22
27
  const Template = require("../Template");
23
28
  const { last, someInIterable } = require("../util/IterableHelpers");
@@ -133,6 +138,8 @@ const printGeneratedCodeForStack = (module, code) => {
133
138
  /** @type {WeakMap<Compilation, CompilationHooks>} */
134
139
  const compilationHooksMap = new WeakMap();
135
140
 
141
+ const PLUGIN_NAME = "JavascriptModulesPlugin";
142
+
136
143
  class JavascriptModulesPlugin {
137
144
  /**
138
145
  * @param {Compilation} compilation the compilation
@@ -196,154 +203,147 @@ class JavascriptModulesPlugin {
196
203
  */
197
204
  apply(compiler) {
198
205
  compiler.hooks.compilation.tap(
199
- "JavascriptModulesPlugin",
206
+ PLUGIN_NAME,
200
207
  (compilation, { normalModuleFactory }) => {
201
208
  const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
202
209
  normalModuleFactory.hooks.createParser
203
- .for("javascript/auto")
204
- .tap("JavascriptModulesPlugin", options => {
210
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
211
+ .tap(PLUGIN_NAME, options => {
205
212
  return new JavascriptParser("auto");
206
213
  });
207
214
  normalModuleFactory.hooks.createParser
208
- .for("javascript/dynamic")
209
- .tap("JavascriptModulesPlugin", options => {
215
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
216
+ .tap(PLUGIN_NAME, options => {
210
217
  return new JavascriptParser("script");
211
218
  });
212
219
  normalModuleFactory.hooks.createParser
213
- .for("javascript/esm")
214
- .tap("JavascriptModulesPlugin", options => {
220
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
221
+ .tap(PLUGIN_NAME, options => {
215
222
  return new JavascriptParser("module");
216
223
  });
217
224
  normalModuleFactory.hooks.createGenerator
218
- .for("javascript/auto")
219
- .tap("JavascriptModulesPlugin", () => {
225
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
226
+ .tap(PLUGIN_NAME, () => {
220
227
  return new JavascriptGenerator();
221
228
  });
222
229
  normalModuleFactory.hooks.createGenerator
223
- .for("javascript/dynamic")
224
- .tap("JavascriptModulesPlugin", () => {
230
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
231
+ .tap(PLUGIN_NAME, () => {
225
232
  return new JavascriptGenerator();
226
233
  });
227
234
  normalModuleFactory.hooks.createGenerator
228
- .for("javascript/esm")
229
- .tap("JavascriptModulesPlugin", () => {
235
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
236
+ .tap(PLUGIN_NAME, () => {
230
237
  return new JavascriptGenerator();
231
238
  });
232
- compilation.hooks.renderManifest.tap(
233
- "JavascriptModulesPlugin",
234
- (result, options) => {
235
- const {
236
- hash,
237
- chunk,
238
- chunkGraph,
239
- moduleGraph,
240
- runtimeTemplate,
241
- dependencyTemplates,
242
- outputOptions,
243
- codeGenerationResults
244
- } = options;
239
+ compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
240
+ const {
241
+ hash,
242
+ chunk,
243
+ chunkGraph,
244
+ moduleGraph,
245
+ runtimeTemplate,
246
+ dependencyTemplates,
247
+ outputOptions,
248
+ codeGenerationResults
249
+ } = options;
245
250
 
246
- const hotUpdateChunk =
247
- chunk instanceof HotUpdateChunk ? chunk : null;
251
+ const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null;
248
252
 
249
- let render;
250
- const filenameTemplate =
251
- JavascriptModulesPlugin.getChunkFilenameTemplate(
252
- chunk,
253
- outputOptions
253
+ let render;
254
+ const filenameTemplate =
255
+ JavascriptModulesPlugin.getChunkFilenameTemplate(
256
+ chunk,
257
+ outputOptions
258
+ );
259
+ if (hotUpdateChunk) {
260
+ render = () =>
261
+ this.renderChunk(
262
+ {
263
+ chunk,
264
+ dependencyTemplates,
265
+ runtimeTemplate,
266
+ moduleGraph,
267
+ chunkGraph,
268
+ codeGenerationResults,
269
+ strictMode: runtimeTemplate.isModule()
270
+ },
271
+ hooks
254
272
  );
255
- if (hotUpdateChunk) {
256
- render = () =>
257
- this.renderChunk(
258
- {
259
- chunk,
260
- dependencyTemplates,
261
- runtimeTemplate,
262
- moduleGraph,
263
- chunkGraph,
264
- codeGenerationResults,
265
- strictMode: runtimeTemplate.isModule()
266
- },
267
- hooks
268
- );
269
- } else if (chunk.hasRuntime()) {
270
- render = () =>
271
- this.renderMain(
272
- {
273
- hash,
274
- chunk,
275
- dependencyTemplates,
276
- runtimeTemplate,
277
- moduleGraph,
278
- chunkGraph,
279
- codeGenerationResults,
280
- strictMode: runtimeTemplate.isModule()
281
- },
282
- hooks,
283
- compilation
284
- );
285
- } else {
286
- if (!chunkHasJs(chunk, chunkGraph)) {
287
- return result;
288
- }
289
-
290
- render = () =>
291
- this.renderChunk(
292
- {
293
- chunk,
294
- dependencyTemplates,
295
- runtimeTemplate,
296
- moduleGraph,
297
- chunkGraph,
298
- codeGenerationResults,
299
- strictMode: runtimeTemplate.isModule()
300
- },
301
- hooks
302
- );
273
+ } else if (chunk.hasRuntime()) {
274
+ render = () =>
275
+ this.renderMain(
276
+ {
277
+ hash,
278
+ chunk,
279
+ dependencyTemplates,
280
+ runtimeTemplate,
281
+ moduleGraph,
282
+ chunkGraph,
283
+ codeGenerationResults,
284
+ strictMode: runtimeTemplate.isModule()
285
+ },
286
+ hooks,
287
+ compilation
288
+ );
289
+ } else {
290
+ if (!chunkHasJs(chunk, chunkGraph)) {
291
+ return result;
303
292
  }
304
293
 
305
- result.push({
306
- render,
307
- filenameTemplate,
308
- pathOptions: {
309
- hash,
310
- runtime: chunk.runtime,
311
- chunk,
312
- contentHashType: "javascript"
313
- },
314
- info: {
315
- javascriptModule: compilation.runtimeTemplate.isModule()
316
- },
317
- identifier: hotUpdateChunk
318
- ? `hotupdatechunk${chunk.id}`
319
- : `chunk${chunk.id}`,
320
- hash: chunk.contentHash.javascript
321
- });
322
-
323
- return result;
324
- }
325
- );
326
- compilation.hooks.chunkHash.tap(
327
- "JavascriptModulesPlugin",
328
- (chunk, hash, context) => {
329
- hooks.chunkHash.call(chunk, hash, context);
330
- if (chunk.hasRuntime()) {
331
- this.updateHashWithBootstrap(
332
- hash,
294
+ render = () =>
295
+ this.renderChunk(
333
296
  {
334
- hash: "0000",
335
297
  chunk,
336
- codeGenerationResults: context.codeGenerationResults,
337
- chunkGraph: context.chunkGraph,
338
- moduleGraph: context.moduleGraph,
339
- runtimeTemplate: context.runtimeTemplate
298
+ dependencyTemplates,
299
+ runtimeTemplate,
300
+ moduleGraph,
301
+ chunkGraph,
302
+ codeGenerationResults,
303
+ strictMode: runtimeTemplate.isModule()
340
304
  },
341
305
  hooks
342
306
  );
343
- }
344
307
  }
345
- );
346
- compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
308
+
309
+ result.push({
310
+ render,
311
+ filenameTemplate,
312
+ pathOptions: {
313
+ hash,
314
+ runtime: chunk.runtime,
315
+ chunk,
316
+ contentHashType: "javascript"
317
+ },
318
+ info: {
319
+ javascriptModule: compilation.runtimeTemplate.isModule()
320
+ },
321
+ identifier: hotUpdateChunk
322
+ ? `hotupdatechunk${chunk.id}`
323
+ : `chunk${chunk.id}`,
324
+ hash: chunk.contentHash.javascript
325
+ });
326
+
327
+ return result;
328
+ });
329
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, context) => {
330
+ hooks.chunkHash.call(chunk, hash, context);
331
+ if (chunk.hasRuntime()) {
332
+ this.updateHashWithBootstrap(
333
+ hash,
334
+ {
335
+ hash: "0000",
336
+ chunk,
337
+ codeGenerationResults: context.codeGenerationResults,
338
+ chunkGraph: context.chunkGraph,
339
+ moduleGraph: context.moduleGraph,
340
+ runtimeTemplate: context.runtimeTemplate
341
+ },
342
+ hooks
343
+ );
344
+ }
345
+ });
346
+ compilation.hooks.contentHash.tap(PLUGIN_NAME, chunk => {
347
347
  const {
348
348
  chunkGraph,
349
349
  codeGenerationResults,
@@ -410,7 +410,7 @@ class JavascriptModulesPlugin {
410
410
  );
411
411
  });
412
412
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
413
- "JavascriptModulesPlugin",
413
+ PLUGIN_NAME,
414
414
  (chunk, set, { chunkGraph }) => {
415
415
  if (
416
416
  !set.has(RuntimeGlobals.startupNoDefault) &&
@@ -421,58 +421,51 @@ class JavascriptModulesPlugin {
421
421
  }
422
422
  }
423
423
  );
424
- compilation.hooks.executeModule.tap(
425
- "JavascriptModulesPlugin",
426
- (options, context) => {
427
- const source =
428
- options.codeGenerationResult.sources.get("javascript");
429
- if (source === undefined) return;
430
- const { module, moduleObject } = options;
431
- const code = source.source();
424
+ compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
425
+ const source = options.codeGenerationResult.sources.get("javascript");
426
+ if (source === undefined) return;
427
+ const { module, moduleObject } = options;
428
+ const code = source.source();
432
429
 
433
- const fn = vm.runInThisContext(
434
- `(function(${module.moduleArgument}, ${module.exportsArgument}, __webpack_require__) {\n${code}\n/**/})`,
435
- {
436
- filename: module.identifier(),
437
- lineOffset: -1
438
- }
439
- );
440
- try {
441
- fn.call(
442
- moduleObject.exports,
443
- moduleObject,
444
- moduleObject.exports,
445
- context.__webpack_require__
446
- );
447
- } catch (e) {
448
- e.stack += printGeneratedCodeForStack(options.module, code);
449
- throw e;
430
+ const fn = vm.runInThisContext(
431
+ `(function(${module.moduleArgument}, ${module.exportsArgument}, __webpack_require__) {\n${code}\n/**/})`,
432
+ {
433
+ filename: module.identifier(),
434
+ lineOffset: -1
450
435
  }
436
+ );
437
+ try {
438
+ fn.call(
439
+ moduleObject.exports,
440
+ moduleObject,
441
+ moduleObject.exports,
442
+ context.__webpack_require__
443
+ );
444
+ } catch (e) {
445
+ e.stack += printGeneratedCodeForStack(options.module, code);
446
+ throw e;
451
447
  }
452
- );
453
- compilation.hooks.executeModule.tap(
454
- "JavascriptModulesPlugin",
455
- (options, context) => {
456
- const source = options.codeGenerationResult.sources.get("runtime");
457
- if (source === undefined) return;
458
- let code = source.source();
459
- if (typeof code !== "string") code = code.toString();
448
+ });
449
+ compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
450
+ const source = options.codeGenerationResult.sources.get("runtime");
451
+ if (source === undefined) return;
452
+ let code = source.source();
453
+ if (typeof code !== "string") code = code.toString();
460
454
 
461
- const fn = vm.runInThisContext(
462
- `(function(__webpack_require__) {\n${code}\n/**/})`,
463
- {
464
- filename: options.module.identifier(),
465
- lineOffset: -1
466
- }
467
- );
468
- try {
469
- fn.call(null, context.__webpack_require__);
470
- } catch (e) {
471
- e.stack += printGeneratedCodeForStack(options.module, code);
472
- throw e;
455
+ const fn = vm.runInThisContext(
456
+ `(function(__webpack_require__) {\n${code}\n/**/})`,
457
+ {
458
+ filename: options.module.identifier(),
459
+ lineOffset: -1
473
460
  }
461
+ );
462
+ try {
463
+ fn.call(null, context.__webpack_require__);
464
+ } catch (e) {
465
+ e.stack += printGeneratedCodeForStack(options.module, code);
466
+ throw e;
474
467
  }
475
- );
468
+ });
476
469
  }
477
470
  );
478
471
  }