webpack 5.21.0 → 5.23.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 (61) hide show
  1. package/lib/ChunkGraph.js +3 -2
  2. package/lib/CodeGenerationResults.js +2 -1
  3. package/lib/Compilation.js +91 -40
  4. package/lib/EvalDevToolModulePlugin.js +4 -0
  5. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  6. package/lib/ExportsInfo.js +1 -0
  7. package/lib/ExternalModule.js +8 -7
  8. package/lib/FlagDependencyUsagePlugin.js +7 -6
  9. package/lib/JavascriptMetaInfoPlugin.js +62 -0
  10. package/lib/LibManifestPlugin.js +1 -13
  11. package/lib/Module.js +2 -3
  12. package/lib/MultiCompiler.js +170 -77
  13. package/lib/MultiStats.js +9 -6
  14. package/lib/NormalModuleFactory.js +135 -22
  15. package/lib/RuntimeGlobals.js +5 -0
  16. package/lib/RuntimePlugin.js +10 -1
  17. package/lib/Watching.js +70 -27
  18. package/lib/WebpackOptionsApply.js +7 -7
  19. package/lib/config/defaults.js +26 -10
  20. package/lib/config/target.js +1 -1
  21. package/lib/container/ContainerEntryModule.js +2 -1
  22. package/lib/dependencies/AMDDefineDependency.js +1 -1
  23. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -0
  24. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  25. package/lib/dependencies/HarmonyExportInitFragment.js +2 -3
  26. package/lib/dependencies/HarmonyImportSpecifierDependency.js +9 -2
  27. package/lib/dependencies/LoaderPlugin.js +9 -2
  28. package/lib/dependencies/URLDependency.js +35 -13
  29. package/lib/dependencies/URLPlugin.js +3 -1
  30. package/lib/dependencies/WorkerPlugin.js +7 -1
  31. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  32. package/lib/index.js +1 -0
  33. package/lib/javascript/CommonJsChunkFormatPlugin.js +15 -4
  34. package/lib/javascript/JavascriptModulesPlugin.js +143 -78
  35. package/lib/javascript/JavascriptParser.js +1 -0
  36. package/lib/json/JsonGenerator.js +29 -8
  37. package/lib/library/AbstractLibraryPlugin.js +108 -32
  38. package/lib/library/AmdLibraryPlugin.js +12 -6
  39. package/lib/library/AssignLibraryPlugin.js +137 -26
  40. package/lib/library/EnableLibraryPlugin.js +18 -7
  41. package/lib/library/ExportPropertyLibraryPlugin.js +16 -5
  42. package/lib/library/JsonpLibraryPlugin.js +3 -1
  43. package/lib/library/ModuleLibraryPlugin.js +100 -0
  44. package/lib/library/SystemLibraryPlugin.js +1 -1
  45. package/lib/node/NodeTargetPlugin.js +1 -1
  46. package/lib/optimize/ConcatenatedModule.js +54 -35
  47. package/lib/optimize/InnerGraph.js +5 -4
  48. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -3
  49. package/lib/runtime/RelativeUrlRuntimeModule.js +41 -0
  50. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -0
  51. package/lib/serialization/ObjectMiddleware.js +34 -19
  52. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -12
  53. package/lib/stats/DefaultStatsPrinterPlugin.js +19 -6
  54. package/lib/util/IterableHelpers.js +46 -0
  55. package/lib/util/LazyBucketSortedSet.js +3 -2
  56. package/lib/util/SetHelpers.js +11 -0
  57. package/lib/webpack.js +56 -50
  58. package/package.json +3 -3
  59. package/schemas/WebpackOptions.json +8 -1
  60. package/types.d.ts +38 -7
  61. package/lib/FlagUsingEvalPlugin.js +0 -44
package/lib/Watching.js CHANGED
@@ -34,6 +34,10 @@ class Watching {
34
34
  this._closeCallbacks = undefined;
35
35
  this.closed = false;
36
36
  this.suspended = false;
37
+ this.blocked = false;
38
+ this._isBlocked = () => false;
39
+ this._onChange = () => {};
40
+ this._onInvalid = () => {};
37
41
  if (typeof watchOptions === "number") {
38
42
  this.watchOptions = {
39
43
  aggregateTimeout: watchOptions
@@ -47,27 +51,59 @@ class Watching {
47
51
  this.watchOptions.aggregateTimeout = 200;
48
52
  }
49
53
  this.compiler = compiler;
50
- this.running = true;
54
+ this.running = false;
55
+ this._initial = true;
56
+ this._needRecords = true;
57
+ this._needWatcherInfo = false;
51
58
  this.watcher = undefined;
52
59
  this.pausedWatcher = undefined;
53
60
  this._done = this._done.bind(this);
54
- this.compiler.readRecords(err => {
55
- if (err) return this._done(err);
56
-
57
- this._go();
61
+ process.nextTick(() => {
62
+ if (this._initial) this._invalidate();
58
63
  });
59
64
  }
60
65
 
61
66
  _go() {
67
+ this._initial = false;
62
68
  this.startTime = Date.now();
63
69
  this.running = true;
64
- this.invalid = false;
65
70
  const run = () => {
71
+ if (this.compiler.idle) {
72
+ return this.compiler.cache.endIdle(err => {
73
+ if (err) return this._done(err);
74
+ this.compiler.idle = false;
75
+ run();
76
+ });
77
+ }
78
+ if (this._needRecords) {
79
+ return this.compiler.readRecords(err => {
80
+ if (err) return this._done(err);
81
+
82
+ this._needRecords = false;
83
+ run();
84
+ });
85
+ }
86
+ this.invalid = false;
87
+ if (this._needWatcherInfo) {
88
+ this._needWatcherInfo = false;
89
+ const watcher = this.pausedWatcher;
90
+ if (watcher) {
91
+ this.compiler.modifiedFiles = watcher.aggregatedChanges;
92
+ this.compiler.removedFiles = watcher.aggregatedRemovals;
93
+ this.compiler.fileTimestamps = watcher.getFileTimeInfoEntries();
94
+ this.compiler.contextTimestamps = watcher.getContextTimeInfoEntries();
95
+ } else {
96
+ this.compiler.modifiedFiles = undefined;
97
+ this.compiler.removedFiles = undefined;
98
+ this.compiler.fileTimestamps = undefined;
99
+ this.compiler.contextTimestamps = undefined;
100
+ }
101
+ }
66
102
  this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
67
103
  if (err) return this._done(err);
68
104
  const onCompiled = (err, compilation) => {
69
105
  if (err) return this._done(err, compilation);
70
- if (this.invalid) return this._done();
106
+ if (this.invalid) return this._done(null, compilation);
71
107
 
72
108
  if (this.compiler.hooks.shouldEmit.call(compilation) === false) {
73
109
  return this._done(null, compilation);
@@ -113,15 +149,7 @@ class Watching {
113
149
  });
114
150
  };
115
151
 
116
- if (this.compiler.idle) {
117
- this.compiler.cache.endIdle(err => {
118
- if (err) return this._done(err);
119
- this.compiler.idle = false;
120
- run();
121
- });
122
- } else {
123
- run();
124
- }
152
+ run();
125
153
  }
126
154
 
127
155
  /**
@@ -154,7 +182,12 @@ class Watching {
154
182
  this.callbacks.length = 0;
155
183
  };
156
184
 
157
- if (this.invalid) {
185
+ if (
186
+ this.invalid &&
187
+ !this.suspended &&
188
+ !this.blocked &&
189
+ !(this._isBlocked() && (this.blocked = true))
190
+ ) {
158
191
  if (compilation) {
159
192
  logger.time("storeBuildDependencies");
160
193
  this.compiler.cache.storeBuildDependencies(
@@ -244,12 +277,12 @@ class Watching {
244
277
  this.compiler.contextTimestamps = contextTimeInfoEntries;
245
278
  this.compiler.removedFiles = removedFiles;
246
279
  this.compiler.modifiedFiles = changedFiles;
247
- if (!this.suspended) {
248
- this._invalidate();
249
- }
280
+ this._invalidate();
281
+ this._onChange();
250
282
  },
251
283
  (fileName, changeTime) => {
252
284
  this.compiler.hooks.invalid.call(fileName, changeTime);
285
+ this._onInvalid();
253
286
  }
254
287
  );
255
288
  }
@@ -262,17 +295,19 @@ class Watching {
262
295
  if (callback) {
263
296
  this.callbacks.push(callback);
264
297
  }
265
- if (this.watcher) {
266
- this.compiler.modifiedFiles = this.watcher.aggregatedChanges;
267
- this.compiler.removedFiles = this.watcher.aggregatedRemovals;
268
- this.compiler.fileTimestamps = this.watcher.getFileTimeInfoEntries();
269
- this.compiler.contextTimestamps = this.watcher.getContextTimeInfoEntries();
298
+ if (!this._initial) {
299
+ this.compiler.hooks.invalid.call(null, Date.now());
300
+ this._needWatcherInfo = true;
270
301
  }
271
- this.compiler.hooks.invalid.call(null, Date.now());
272
302
  this._invalidate();
273
303
  }
274
304
 
275
305
  _invalidate() {
306
+ if (this.suspended) return;
307
+ if (this._isBlocked()) {
308
+ this.blocked = true;
309
+ return;
310
+ }
276
311
  if (this.watcher) {
277
312
  this.pausedWatcher = this.watcher;
278
313
  this.watcher.pause();
@@ -288,12 +323,20 @@ class Watching {
288
323
 
289
324
  suspend() {
290
325
  this.suspended = true;
291
- this.invalid = false;
292
326
  }
293
327
 
294
328
  resume() {
295
329
  if (this.suspended) {
296
330
  this.suspended = false;
331
+ this._needWatcherInfo = true;
332
+ this._invalidate();
333
+ }
334
+ }
335
+
336
+ _checkUnblocked() {
337
+ if (this.blocked && !this._isBlocked()) {
338
+ this.blocked = false;
339
+ this._needWatcherInfo = true;
297
340
  this._invalidate();
298
341
  }
299
342
  }
@@ -43,10 +43,11 @@ const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
43
43
  const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
44
44
  const SystemPlugin = require("./dependencies/SystemPlugin");
45
45
  const URLPlugin = require("./dependencies/URLPlugin");
46
+ const WorkerPlugin = require("./dependencies/WorkerPlugin");
46
47
 
47
48
  const InferAsyncModulesPlugin = require("./async-modules/InferAsyncModulesPlugin");
48
49
 
49
- const FlagUsingEvalPlugin = require("./FlagUsingEvalPlugin");
50
+ const JavascriptMetaInfoPlugin = require("./JavascriptMetaInfoPlugin");
50
51
  const DefaultStatsFactoryPlugin = require("./stats/DefaultStatsFactoryPlugin");
51
52
  const DefaultStatsPresetPlugin = require("./stats/DefaultStatsPresetPlugin");
52
53
  const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
@@ -312,17 +313,16 @@ class WebpackOptionsApply extends OptionsApply {
312
313
  new SystemPlugin().apply(compiler);
313
314
  new ImportMetaPlugin().apply(compiler);
314
315
  new URLPlugin().apply(compiler);
315
-
316
- if (options.output.workerChunkLoading) {
317
- const WorkerPlugin = require("./dependencies/WorkerPlugin");
318
- new WorkerPlugin(options.output.workerChunkLoading).apply(compiler);
319
- }
316
+ new WorkerPlugin(
317
+ options.output.workerChunkLoading,
318
+ options.output.workerWasmLoading
319
+ ).apply(compiler);
320
320
 
321
321
  new DefaultStatsFactoryPlugin().apply(compiler);
322
322
  new DefaultStatsPresetPlugin().apply(compiler);
323
323
  new DefaultStatsPrinterPlugin().apply(compiler);
324
324
 
325
- new FlagUsingEvalPlugin().apply(compiler);
325
+ new JavascriptMetaInfoPlugin().apply(compiler);
326
326
 
327
327
  if (typeof options.mode !== "string") {
328
328
  const WarnNoModeSetPlugin = require("./WarnNoModeSetPlugin");
@@ -622,11 +622,19 @@ const applyOutputDefaults = (
622
622
  });
623
623
  F(output, "chunkLoading", () => {
624
624
  if (tp) {
625
- if (tp.document) return "jsonp";
626
- if (tp.require) return "require";
627
- if (tp.nodeBuiltins) return "async-node";
628
- if (tp.importScripts) return "import-scripts";
629
- if (tp.dynamicImport && output.module) return "import";
625
+ switch (output.chunkFormat) {
626
+ case "array-push":
627
+ if (tp.document) return "jsonp";
628
+ if (tp.importScripts) return "import-scripts";
629
+ break;
630
+ case "commonjs":
631
+ if (tp.require) return "require";
632
+ if (tp.nodeBuiltins) return "async-node";
633
+ break;
634
+ case "module":
635
+ if (tp.dynamicImport) return "import";
636
+ break;
637
+ }
630
638
  if (
631
639
  tp.require === null ||
632
640
  tp.nodeBuiltins === null ||
@@ -640,10 +648,18 @@ const applyOutputDefaults = (
640
648
  });
641
649
  F(output, "workerChunkLoading", () => {
642
650
  if (tp) {
643
- if (tp.require) return "require";
644
- if (tp.nodeBuiltins) return "async-node";
645
- if (tp.importScriptsInWorker) return "import-scripts";
646
- if (tp.dynamicImportInWorker && output.module) return "import";
651
+ switch (output.chunkFormat) {
652
+ case "array-push":
653
+ if (tp.importScriptsInWorker) return "import-scripts";
654
+ break;
655
+ case "commonjs":
656
+ if (tp.require) return "require";
657
+ if (tp.nodeBuiltins) return "async-node";
658
+ break;
659
+ case "module":
660
+ if (tp.dynamicImportInWorker) return "import";
661
+ break;
662
+ }
647
663
  if (
648
664
  tp.require === null ||
649
665
  tp.nodeBuiltins === null ||
@@ -656,8 +672,8 @@ const applyOutputDefaults = (
656
672
  });
657
673
  F(output, "wasmLoading", () => {
658
674
  if (tp) {
659
- if (tp.nodeBuiltins) return "async-node";
660
675
  if (tp.fetchWasm) return "fetch";
676
+ if (tp.nodeBuiltins) return "async-node";
661
677
  if (tp.nodeBuiltins === null || tp.fetchWasm === null) {
662
678
  return "universal";
663
679
  }
@@ -197,7 +197,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
197
197
  document: context === "renderer",
198
198
  fetchWasm: context === "renderer",
199
199
  importScripts: false,
200
- importScriptsInWorker: false,
200
+ importScriptsInWorker: true,
201
201
 
202
202
  globalThis: v(5),
203
203
  const: v(1, 1),
@@ -101,7 +101,8 @@ class ContainerEntryModule extends Module {
101
101
  build(options, compilation, resolver, fs, callback) {
102
102
  this.buildMeta = {};
103
103
  this.buildInfo = {
104
- strict: true
104
+ strict: true,
105
+ topLevelDeclarations: new Set(["moduleMap", "get", "init"])
105
106
  };
106
107
 
107
108
  this.clearDependenciesAndBlocks();
@@ -68,7 +68,7 @@ const DEFINITIONS = {
68
68
  lf: {
69
69
  definition: "var XXX, XXXmodule;",
70
70
  content:
71
- "!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = #.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))",
71
+ "!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))",
72
72
  requests: [RuntimeGlobals.require, RuntimeGlobals.module]
73
73
  },
74
74
  lo: {
@@ -276,6 +276,10 @@ class AMDDefineDependencyParserPlugin {
276
276
  }
277
277
  parser.scope.inTry = inTry;
278
278
  if (fn.body.type === "BlockStatement") {
279
+ parser.detectMode(fn.body.body);
280
+ const prev = parser.prevStatement;
281
+ parser.preWalkStatement(fn.body);
282
+ parser.prevStatement = prev;
279
283
  parser.walkStatement(fn.body);
280
284
  } else {
281
285
  parser.walkExpression(fn.body);
@@ -293,6 +297,10 @@ class AMDDefineDependencyParserPlugin {
293
297
  }
294
298
  parser.scope.inTry = inTry;
295
299
  if (fn.callee.object.body.type === "BlockStatement") {
300
+ parser.detectMode(fn.callee.object.body.body);
301
+ const prev = parser.prevStatement;
302
+ parser.preWalkStatement(fn.callee.object.body);
303
+ parser.prevStatement = prev;
296
304
  parser.walkStatement(fn.callee.object.body);
297
305
  } else {
298
306
  parser.walkExpression(fn.callee.object.body);
@@ -11,6 +11,7 @@ const HarmonyLinkingError = require("../HarmonyLinkingError");
11
11
  const InitFragment = require("../InitFragment");
12
12
  const RuntimeGlobals = require("../RuntimeGlobals");
13
13
  const Template = require("../Template");
14
+ const { first } = require("../util/SetHelpers");
14
15
  const makeSerializable = require("../util/makeSerializable");
15
16
  const propertyAccess = require("../util/propertyAccess");
16
17
  const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
@@ -921,7 +922,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
921
922
  ".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
922
923
  } else if (ignored.size === 1) {
923
924
  content += `if(__WEBPACK_IMPORT_KEY__ !== ${JSON.stringify(
924
- ignored.values().next().value
925
+ first(ignored)
925
926
  )}) `;
926
927
  }
927
928
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  const InitFragment = require("../InitFragment");
9
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
+ const { first } = require("../util/SetHelpers");
10
11
 
11
12
  /** @typedef {import("webpack-sources").Source} Source */
12
13
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
@@ -91,9 +92,7 @@ class HarmonyExportInitFragment extends InitFragment {
91
92
  this.unusedExports
92
93
  )} */\n`
93
94
  : this.unusedExports.size > 0
94
- ? `/* unused harmony export ${
95
- this.unusedExports.values().next().value
96
- } */\n`
95
+ ? `/* unused harmony export ${first(this.unusedExports)} */\n`
97
96
  : "";
98
97
  const definitions = [];
99
98
  for (const [key, value] of this.exportMap) {
@@ -111,7 +111,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
111
111
  */
112
112
  getReferencedExports(moduleGraph, runtime) {
113
113
  let ids = this.getIds(moduleGraph);
114
- if (ids.length > 0 && ids[0] === "default") {
114
+ if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED;
115
+ let namespaceObjectAsContext = this.namespaceObjectAsContext;
116
+ if (ids[0] === "default") {
115
117
  const selfModule = moduleGraph.getParentModule(this);
116
118
  const importedModule = moduleGraph.getModule(this);
117
119
  switch (
@@ -124,13 +126,18 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
124
126
  case "default-with-named":
125
127
  if (ids.length === 1) return Dependency.EXPORTS_OBJECT_REFERENCED;
126
128
  ids = ids.slice(1);
129
+ namespaceObjectAsContext = true;
127
130
  break;
128
131
  case "dynamic":
129
132
  return Dependency.EXPORTS_OBJECT_REFERENCED;
130
133
  }
131
134
  }
132
135
 
133
- if (this.namespaceObjectAsContext) {
136
+ if (
137
+ this.call &&
138
+ !this.directImport &&
139
+ (namespaceObjectAsContext || ids.length > 1)
140
+ ) {
134
141
  if (ids.length === 1) return Dependency.EXPORTS_OBJECT_REFERENCED;
135
142
  ids = ids.slice(0, -1);
136
143
  }
@@ -74,10 +74,17 @@ class LoaderPlugin {
74
74
  if (!referencedModule) {
75
75
  return callback(new Error("Cannot load the module"));
76
76
  }
77
+ if (referencedModule.getNumberOfErrors() > 0) {
78
+ return callback(
79
+ new Error("The loaded module contains errors")
80
+ );
81
+ }
77
82
  const moduleSource = referencedModule.originalSource();
78
83
  if (!moduleSource) {
79
- throw new Error(
80
- "The module created for a LoaderDependency must have an original source"
84
+ return callback(
85
+ new Error(
86
+ "The module created for a LoaderDependency must have an original source"
87
+ )
81
88
  );
82
89
  }
83
90
  let source, map;
@@ -28,11 +28,13 @@ class URLDependency extends ModuleDependency {
28
28
  * @param {string} request request
29
29
  * @param {[number, number]} range range of the arguments of new URL( |> ... <| )
30
30
  * @param {[number, number]} outerRange range of the full |> new URL(...) <|
31
+ * @param {boolean=} relative use relative urls instead of absolute with base uri
31
32
  */
32
- constructor(request, range, outerRange) {
33
+ constructor(request, range, outerRange, relative) {
33
34
  super(request);
34
35
  this.range = range;
35
36
  this.outerRange = outerRange;
37
+ this.relative = relative || false;
36
38
  /** @type {Set<string> | boolean} */
37
39
  this.usedByExports = undefined;
38
40
  }
@@ -60,6 +62,7 @@ class URLDependency extends ModuleDependency {
60
62
  serialize(context) {
61
63
  const { write } = context;
62
64
  write(this.outerRange);
65
+ write(this.relative);
63
66
  write(this.usedByExports);
64
67
  super.serialize(context);
65
68
  }
@@ -67,6 +70,7 @@ class URLDependency extends ModuleDependency {
67
70
  deserialize(context) {
68
71
  const { read } = context;
69
72
  this.outerRange = read();
73
+ this.relative = read();
70
74
  this.usedByExports = read();
71
75
  super.deserialize(context);
72
76
  }
@@ -101,20 +105,38 @@ URLDependency.Template = class URLDependencyTemplate extends (
101
105
  return;
102
106
  }
103
107
 
104
- runtimeRequirements.add(RuntimeGlobals.baseURI);
105
108
  runtimeRequirements.add(RuntimeGlobals.require);
106
109
 
107
- source.replace(
108
- dep.range[0],
109
- dep.range[1] - 1,
110
- `/* asset import */ ${runtimeTemplate.moduleRaw({
111
- chunkGraph,
112
- module: moduleGraph.getModule(dep),
113
- request: dep.request,
114
- runtimeRequirements,
115
- weak: false
116
- })}, ${RuntimeGlobals.baseURI}`
117
- );
110
+ if (dep.relative) {
111
+ runtimeRequirements.add(RuntimeGlobals.relativeUrl);
112
+ source.replace(
113
+ dep.outerRange[0],
114
+ dep.outerRange[1] - 1,
115
+ `/* asset import */ new ${
116
+ RuntimeGlobals.relativeUrl
117
+ }(${runtimeTemplate.moduleRaw({
118
+ chunkGraph,
119
+ module: moduleGraph.getModule(dep),
120
+ request: dep.request,
121
+ runtimeRequirements,
122
+ weak: false
123
+ })})`
124
+ );
125
+ } else {
126
+ runtimeRequirements.add(RuntimeGlobals.baseURI);
127
+
128
+ source.replace(
129
+ dep.range[0],
130
+ dep.range[1] - 1,
131
+ `/* asset import */ ${runtimeTemplate.moduleRaw({
132
+ chunkGraph,
133
+ module: moduleGraph.getModule(dep),
134
+ request: dep.request,
135
+ runtimeRequirements,
136
+ weak: false
137
+ })}, ${RuntimeGlobals.baseURI}`
138
+ );
139
+ }
118
140
  }
119
141
  };
120
142
 
@@ -33,6 +33,7 @@ class URLPlugin {
33
33
  */
34
34
  const parserCallback = (parser, parserOptions) => {
35
35
  if (parserOptions.url === false) return;
36
+ const relative = parserOptions.url === "relative";
36
37
 
37
38
  /**
38
39
  * @param {NewExpressionNode} expr expression
@@ -77,7 +78,8 @@ class URLPlugin {
77
78
  const dep = new URLDependency(
78
79
  request,
79
80
  [arg1.range[0], arg2.range[1]],
80
- expr.range
81
+ expr.range,
82
+ relative
81
83
  );
82
84
  dep.loc = expr.loc;
83
85
  parser.state.module.addDependency(dep);
@@ -13,6 +13,7 @@ const formatLocation = require("../formatLocation");
13
13
  const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
14
14
  const { equals } = require("../util/ArrayHelpers");
15
15
  const { contextify } = require("../util/identifier");
16
+ const EnableWasmLoadingPlugin = require("../wasm/EnableWasmLoadingPlugin");
16
17
  const {
17
18
  harmonySpecifierTag
18
19
  } = require("./HarmonyImportDependencyParserPlugin");
@@ -37,8 +38,9 @@ const DEFAULT_SYNTAX = [
37
38
  ];
38
39
 
39
40
  class WorkerPlugin {
40
- constructor(chunkLoading) {
41
+ constructor(chunkLoading, wasmLoading) {
41
42
  this._chunkLoading = chunkLoading;
43
+ this._wasmLoading = wasmLoading;
42
44
  }
43
45
  /**
44
46
  * Apply the plugin
@@ -49,6 +51,9 @@ class WorkerPlugin {
49
51
  if (this._chunkLoading) {
50
52
  new EnableChunkLoadingPlugin(this._chunkLoading).apply(compiler);
51
53
  }
54
+ if (this._wasmLoading) {
55
+ new EnableWasmLoadingPlugin(this._wasmLoading).apply(compiler);
56
+ }
52
57
  const cachedContextify = contextify.bindContextCache(
53
58
  compiler.context,
54
59
  compiler.root
@@ -227,6 +232,7 @@ class WorkerPlugin {
227
232
  name: entryOptions.name,
228
233
  entryOptions: {
229
234
  chunkLoading: this._chunkLoading,
235
+ wasmLoading: this._wasmLoading,
230
236
  ...entryOptions
231
237
  }
232
238
  });
@@ -199,9 +199,9 @@ class LazyCompilationProxyModule extends Module {
199
199
  `var data = ${JSON.stringify(this.data)};`
200
200
  ]);
201
201
  const keepActive = Template.asString([
202
- `var dispose = client.keepAlive({ data, active: ${JSON.stringify(
202
+ `var dispose = client.keepAlive({ data: data, active: ${JSON.stringify(
203
203
  !!block
204
- )}, module, onError });`
204
+ )}, module: module, onError: onError });`
205
205
  ]);
206
206
  let source;
207
207
  if (block) {
package/lib/index.js CHANGED
@@ -25,6 +25,7 @@ const memoize = require("./util/memoize");
25
25
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
26
26
  /** @typedef {import("./Compilation").Asset} Asset */
27
27
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
28
+ /** @typedef {import("./MultiStats")} MultiStats */
28
29
  /** @typedef {import("./Parser").ParserState} ParserState */
29
30
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
30
31
 
@@ -115,18 +115,29 @@ class CommonJsChunkFormatPlugin {
115
115
  entrySource.add(
116
116
  `${RuntimeGlobals.externalInstallChunk}(exports);\n`
117
117
  );
118
+ const startupSource = new ConcatSource();
118
119
  for (let i = 0; i < entries.length; i++) {
119
120
  const [module, entrypoint] = entries[i];
120
- entrySource.add(
121
- `${i === entries.length - 1 ? "return " : ""}${
122
- RuntimeGlobals.startupEntrypoint
123
- }(${JSON.stringify(
121
+ startupSource.add(
122
+ `${
123
+ i === entries.length - 1 ? "var __webpack_exports__ = " : ""
124
+ }${RuntimeGlobals.startupEntrypoint}(${JSON.stringify(
124
125
  entrypoint.chunks
125
126
  .filter(c => c !== chunk && c !== runtimeChunk)
126
127
  .map(c => c.id)
127
128
  )}, ${JSON.stringify(chunkGraph.getModuleId(module))});\n`
128
129
  );
129
130
  }
131
+ entrySource.add(
132
+ hooks.renderStartup.call(
133
+ startupSource,
134
+ entries[entries.length - 1][0],
135
+ {
136
+ ...renderContext,
137
+ inlined: false
138
+ }
139
+ )
140
+ );
130
141
  entrySource.add("})()");
131
142
  return entrySource;
132
143
  }