webpack 4.8.2 → 4.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +95 -52
  2. package/bin/webpack.js +128 -43
  3. package/lib/AmdMainTemplatePlugin.js +10 -0
  4. package/lib/AsyncDependencyToInitialChunkError.js +12 -2
  5. package/lib/BannerPlugin.js +115 -101
  6. package/lib/CaseSensitiveModulesWarning.js +20 -2
  7. package/lib/Chunk.js +1 -0
  8. package/lib/ChunkGroup.js +465 -465
  9. package/lib/ChunkRenderError.js +8 -0
  10. package/lib/ChunkTemplate.js +71 -71
  11. package/lib/Compilation.js +1 -1
  12. package/lib/Compiler.js +2 -1
  13. package/lib/ContextModule.js +8 -8
  14. package/lib/DllPlugin.js +3 -1
  15. package/lib/DllReferencePlugin.js +2 -1
  16. package/lib/Entrypoint.js +54 -54
  17. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
  18. package/lib/ExportPropertyMainTemplatePlugin.js +13 -0
  19. package/lib/Generator.js +52 -52
  20. package/lib/HotModuleReplacement.runtime.js +633 -633
  21. package/lib/JsonParser.js +2 -1
  22. package/lib/LibManifestPlugin.js +9 -0
  23. package/lib/LibraryTemplatePlugin.js +66 -33
  24. package/lib/MainTemplate.js +468 -468
  25. package/lib/Module.js +3 -3
  26. package/lib/ModuleDependencyError.js +12 -2
  27. package/lib/NormalModuleFactory.js +5 -3
  28. package/lib/Parser.js +27 -23
  29. package/lib/ProgressPlugin.js +1 -1
  30. package/lib/RecordIdsPlugin.js +3 -1
  31. package/lib/RuntimeTemplate.js +1 -1
  32. package/lib/SetVarMainTemplatePlugin.js +12 -0
  33. package/lib/SourceMapDevToolPlugin.js +11 -13
  34. package/lib/Template.js +289 -290
  35. package/lib/UmdMainTemplatePlugin.js +67 -32
  36. package/lib/WebpackError.js +8 -2
  37. package/lib/compareLocations.js +20 -0
  38. package/lib/debug/ProfilingPlugin.js +416 -416
  39. package/lib/dependencies/ContextDependencyHelpers.js +142 -142
  40. package/lib/dependencies/WebpackMissingModule.js +2 -2
  41. package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -40
  42. package/lib/optimize/RuntimeChunkPlugin.js +9 -5
  43. package/lib/optimize/SplitChunksPlugin.js +195 -124
  44. package/lib/util/Queue.js +46 -46
  45. package/lib/util/SetHelpers.js +48 -48
  46. package/lib/util/SortableSet.js +106 -106
  47. package/lib/util/StackedSetMap.js +128 -128
  48. package/lib/util/cachedMerge.js +13 -0
  49. package/lib/util/identifier.js +5 -0
  50. package/lib/util/objectToMap.js +16 -16
  51. package/lib/wasm/WebAssemblyGenerator.js +280 -280
  52. package/lib/wasm/WebAssemblyParser.js +79 -79
  53. package/lib/web/JsonpMainTemplatePlugin.js +2 -2
  54. package/package.json +21 -17
  55. package/schemas/WebpackOptions.json +12 -1
  56. package/schemas/plugins/BannerPlugin.json +96 -85
  57. package/schemas/plugins/DllPlugin.json +4 -0
package/lib/Module.js CHANGED
@@ -11,8 +11,8 @@ const ModuleReason = require("./ModuleReason");
11
11
  const SortableSet = require("./util/SortableSet");
12
12
  const Template = require("./Template");
13
13
 
14
- /** @typedef {typeof import("./Chunk")} Chunk */
15
- /** @typedef {typeof import("./RequestShortener")} RequestShortener */
14
+ /** @typedef {import("./Chunk")} Chunk */
15
+ /** @typedef {import("./RequestShortener")} RequestShortener */
16
16
 
17
17
  const EMPTY_RESOLVE_OPTIONS = {};
18
18
 
@@ -69,7 +69,7 @@ class Module extends DependenciesBlock {
69
69
  this._chunks = new SortableSet(undefined, sortById);
70
70
 
71
71
  // Info from Compilation (per Compilation)
72
- /** @type {number | string} */
72
+ /** @type {number|string} */
73
73
  this.id = null;
74
74
  /** @type {number} */
75
75
  this.index = null;
@@ -7,7 +7,15 @@
7
7
  const WebpackError = require("./WebpackError");
8
8
  const formatLocation = require("./formatLocation");
9
9
 
10
- module.exports = class ModuleDependencyError extends WebpackError {
10
+ /** @typedef {import("./Module")} Module */
11
+
12
+ class ModuleDependencyError extends WebpackError {
13
+ /**
14
+ * Creates an instance of ModuleDependencyError.
15
+ * @param {Module} module module tied to dependency
16
+ * @param {Error} err error thrown
17
+ * @param {TODO} loc location of dependency
18
+ */
11
19
  constructor(module, err, loc) {
12
20
  super();
13
21
 
@@ -22,4 +30,6 @@ module.exports = class ModuleDependencyError extends WebpackError {
22
30
 
23
31
  Error.captureStackTrace(this, this.constructor);
24
32
  }
25
- };
33
+ }
34
+
35
+ module.exports = ModuleDependencyError;
@@ -46,6 +46,8 @@ const identToLoaderRequest = resultString => {
46
46
  }
47
47
  };
48
48
 
49
+ const dependencyCache = new WeakMap();
50
+
49
51
  class NormalModuleFactory extends Tapable {
50
52
  constructor(context, resolverFactory, options) {
51
53
  super();
@@ -329,7 +331,7 @@ class NormalModuleFactory extends Tapable {
329
331
 
330
332
  create(data, callback) {
331
333
  const dependencies = data.dependencies;
332
- const cacheEntry = dependencies[0].__NormalModuleFactoryCache;
334
+ const cacheEntry = dependencyCache.get(dependencies[0]);
333
335
  if (cacheEntry) return callback(null, cacheEntry);
334
336
  const context = data.context || this.context;
335
337
  const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
@@ -359,7 +361,7 @@ class NormalModuleFactory extends Tapable {
359
361
 
360
362
  if (module && this.cachePredicate(module)) {
361
363
  for (const d of dependencies) {
362
- d.__NormalModuleFactoryCache = module;
364
+ dependencyCache.set(d, module);
363
365
  }
364
366
  }
365
367
 
@@ -399,7 +401,7 @@ class NormalModuleFactory extends Tapable {
399
401
  ` You need to specify '${
400
402
  item.loader
401
403
  }-loader' instead of '${item.loader}',\n` +
402
- " see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed";
404
+ " see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed";
403
405
  }
404
406
  callback(err);
405
407
  }
package/lib/Parser.js CHANGED
@@ -1030,23 +1030,28 @@ class Parser extends Tapable {
1030
1030
  }
1031
1031
 
1032
1032
  walkForInStatement(statement) {
1033
- if (statement.left.type === "VariableDeclaration")
1033
+ if (statement.left.type === "VariableDeclaration") {
1034
1034
  this.walkVariableDeclaration(statement.left);
1035
- else this.walkPattern(statement.left);
1035
+ } else {
1036
+ this.walkPattern(statement.left);
1037
+ }
1036
1038
  this.walkExpression(statement.right);
1037
1039
  this.walkStatement(statement.body);
1038
1040
  }
1039
1041
 
1040
1042
  prewalkForOfStatement(statement) {
1041
- if (statement.left.type === "VariableDeclaration")
1043
+ if (statement.left.type === "VariableDeclaration") {
1042
1044
  this.prewalkVariableDeclaration(statement.left);
1045
+ }
1043
1046
  this.prewalkStatement(statement.body);
1044
1047
  }
1045
1048
 
1046
1049
  walkForOfStatement(statement) {
1047
- if (statement.left.type === "VariableDeclaration")
1050
+ if (statement.left.type === "VariableDeclaration") {
1048
1051
  this.walkVariableDeclaration(statement.left);
1049
- else this.walkPattern(statement.left);
1052
+ } else {
1053
+ this.walkPattern(statement.left);
1054
+ }
1050
1055
  this.walkExpression(statement.right);
1051
1056
  this.walkStatement(statement.body);
1052
1057
  }
@@ -1062,8 +1067,10 @@ class Parser extends Tapable {
1062
1067
  walkFunctionDeclaration(statement) {
1063
1068
  const wasTopLevel = this.scope.topLevelScope;
1064
1069
  this.scope.topLevelScope = false;
1065
- for (const param of statement.params) this.walkPattern(param);
1066
1070
  this.inScope(statement.params, () => {
1071
+ for (const param of statement.params) {
1072
+ this.walkPattern(param);
1073
+ }
1067
1074
  if (statement.body.type === "BlockStatement") {
1068
1075
  this.detectStrictMode(statement.body.body);
1069
1076
  this.prewalkStatement(statement.body);
@@ -1355,13 +1362,10 @@ class Parser extends Tapable {
1355
1362
  }
1356
1363
 
1357
1364
  walkExpressions(expressions) {
1358
- for (
1359
- let expressionsIndex = 0, len = expressions.length;
1360
- expressionsIndex < len;
1361
- expressionsIndex++
1362
- ) {
1363
- const expression = expressions[expressionsIndex];
1364
- if (expression) this.walkExpression(expression);
1365
+ for (const expression of expressions) {
1366
+ if (expression) {
1367
+ this.walkExpression(expression);
1368
+ }
1365
1369
  }
1366
1370
  }
1367
1371
 
@@ -1469,8 +1473,10 @@ class Parser extends Tapable {
1469
1473
  walkFunctionExpression(expression) {
1470
1474
  const wasTopLevel = this.scope.topLevelScope;
1471
1475
  this.scope.topLevelScope = false;
1472
- for (const param of expression.params) this.walkPattern(param);
1473
1476
  this.inScope(expression.params, () => {
1477
+ for (const param of expression.params) {
1478
+ this.walkPattern(param);
1479
+ }
1474
1480
  if (expression.body.type === "BlockStatement") {
1475
1481
  this.detectStrictMode(expression.body.body);
1476
1482
  this.prewalkStatement(expression.body);
@@ -1483,8 +1489,10 @@ class Parser extends Tapable {
1483
1489
  }
1484
1490
 
1485
1491
  walkArrowFunctionExpression(expression) {
1486
- for (const param of expression.params) this.walkPattern(param);
1487
1492
  this.inScope(expression.params, () => {
1493
+ for (const param of expression.params) {
1494
+ this.walkPattern(param);
1495
+ }
1488
1496
  if (expression.body.type === "BlockStatement") {
1489
1497
  this.detectStrictMode(expression.body.body);
1490
1498
  this.prewalkStatement(expression.body);
@@ -1640,7 +1648,9 @@ class Parser extends Tapable {
1640
1648
  if (functionExpression.body.type === "BlockStatement") {
1641
1649
  this.prewalkStatement(functionExpression.body);
1642
1650
  this.walkStatement(functionExpression.body);
1643
- } else this.walkExpression(functionExpression.body);
1651
+ } else {
1652
+ this.walkExpression(functionExpression.body);
1653
+ }
1644
1654
  });
1645
1655
  this.scope.topLevelScope = wasTopLevel;
1646
1656
  }
@@ -1743,13 +1753,7 @@ class Parser extends Tapable {
1743
1753
 
1744
1754
  this.scope.renames.set("this", null);
1745
1755
 
1746
- for (
1747
- let paramIndex = 0, len = params.length;
1748
- paramIndex < len;
1749
- paramIndex++
1750
- ) {
1751
- const param = params[paramIndex];
1752
-
1756
+ for (const param of params) {
1753
1757
  if (typeof param !== "string") {
1754
1758
  this.enterPattern(param, param => {
1755
1759
  this.scope.renames.set(param, null);
@@ -83,7 +83,7 @@ class ProgressPlugin {
83
83
  const states = new Array(compiler.compilers.length);
84
84
  compiler.compilers.forEach((compiler, idx) => {
85
85
  new ProgressPlugin((p, msg, ...args) => {
86
- states[idx] = args;
86
+ states[idx] = [p, msg, ...args];
87
87
  handler(
88
88
  states
89
89
  .map(state => (state && state[0]) || 0)
@@ -21,6 +21,7 @@ class RecordIdsPlugin {
21
21
  if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
22
22
  if (!records.modules.usedIds) records.modules.usedIds = {};
23
23
  for (const module of modules) {
24
+ if (typeof module.id !== "number") continue;
24
25
  const identifier = portableIds
25
26
  ? identifierUtils.makePathsRelative(
26
27
  compiler.context,
@@ -110,6 +111,7 @@ class RecordIdsPlugin {
110
111
  if (!records.chunks.bySource) records.chunks.bySource = {};
111
112
  const usedIds = new Set();
112
113
  for (const chunk of chunks) {
114
+ if (typeof chunk.id !== "number") continue;
113
115
  const name = chunk.name;
114
116
  if (name) records.chunks.byName[name] = chunk.id;
115
117
  const sources = getChunkSources(chunk);
@@ -118,7 +120,7 @@ class RecordIdsPlugin {
118
120
  }
119
121
  usedIds.add(chunk.id);
120
122
  }
121
- records.chunks.usedIds = Array.from(usedIds);
123
+ records.chunks.usedIds = Array.from(usedIds).sort();
122
124
  }
123
125
  );
124
126
  compilation.hooks.reviveChunks.tap(
@@ -44,7 +44,7 @@ module.exports = class RuntimeTemplate {
44
44
  }
45
45
 
46
46
  throwMissingModuleErrorFunction({ request }) {
47
- const err = `Cannot find module "${request}"`;
47
+ const err = `Cannot find module '${request}'`;
48
48
  return `function webpackMissingModule() { var e = new Error(${JSON.stringify(
49
49
  err
50
50
  )}); e.code = 'MODULE_NOT_FOUND'; throw e; }`;
@@ -6,12 +6,24 @@
6
6
 
7
7
  const { ConcatSource } = require("webpack-sources");
8
8
 
9
+ /** @typedef {import("./Compilation")} Compilation */
10
+
9
11
  class SetVarMainTemplatePlugin {
12
+ /**
13
+ * @param {string} varExpression the accessor where the library is exported
14
+ * @param {boolean} copyObject specify copying the exports
15
+ */
10
16
  constructor(varExpression, copyObject) {
17
+ /** @type {string} */
11
18
  this.varExpression = varExpression;
19
+ /** @type {boolean} */
12
20
  this.copyObject = copyObject;
13
21
  }
14
22
 
23
+ /**
24
+ * @param {Compilation} compilation the compilation instance
25
+ * @returns {void}
26
+ */
15
27
  apply(compilation) {
16
28
  const { mainTemplate, chunkTemplate } = compilation;
17
29
 
@@ -18,12 +18,14 @@ const basename = name => {
18
18
  return name.substr(name.lastIndexOf("/") + 1);
19
19
  };
20
20
 
21
+ const assetsCache = new WeakMap();
22
+
21
23
  const getTaskForFile = (file, chunk, options, compilation) => {
22
24
  const asset = compilation.assets[file];
23
- if (asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
24
- const data = asset.__SourceMapDevToolData;
25
- for (const cachedFile in data) {
26
- compilation.assets[cachedFile] = data[cachedFile];
25
+ const cache = assetsCache.get(asset);
26
+ if (cache && cache.file === file) {
27
+ for (const cachedFile in cache.assets) {
28
+ compilation.assets[cachedFile] = cache.assets[cachedFile];
27
29
  if (cachedFile !== file) chunk.files.push(cachedFile);
28
30
  }
29
31
  return;
@@ -207,6 +209,7 @@ class SourceMapDevToolPlugin {
207
209
  task.file,
208
210
  "attach SourceMap"
209
211
  );
212
+ const assets = Object.create(null);
210
213
  const chunk = task.chunk;
211
214
  const file = task.file;
212
215
  const asset = task.asset;
@@ -222,8 +225,7 @@ class SourceMapDevToolPlugin {
222
225
  }
223
226
  sourceMap.sourceRoot = options.sourceRoot || "";
224
227
  sourceMap.file = file;
225
- asset.__SourceMapDevToolFile = file;
226
- asset.__SourceMapDevToolData = {};
228
+ assetsCache.set(asset, { file, assets });
227
229
  let currentSourceMappingURLComment = sourceMappingURLComment;
228
230
  if (
229
231
  currentSourceMappingURLComment !== false &&
@@ -260,9 +262,7 @@ class SourceMapDevToolPlugin {
260
262
  .relative(path.dirname(file), sourceMapFile)
261
263
  .replace(/\\/g, "/");
262
264
  if (currentSourceMappingURLComment !== false) {
263
- asset.__SourceMapDevToolData[file] = compilation.assets[
264
- file
265
- ] = new ConcatSource(
265
+ assets[file] = compilation.assets[file] = new ConcatSource(
266
266
  new RawSource(source),
267
267
  currentSourceMappingURLComment.replace(
268
268
  /\[url\]/g,
@@ -270,14 +270,12 @@ class SourceMapDevToolPlugin {
270
270
  )
271
271
  );
272
272
  }
273
- asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[
273
+ assets[sourceMapFile] = compilation.assets[
274
274
  sourceMapFile
275
275
  ] = new RawSource(sourceMapString);
276
276
  chunk.files.push(sourceMapFile);
277
277
  } else {
278
- asset.__SourceMapDevToolData[file] = compilation.assets[
279
- file
280
- ] = new ConcatSource(
278
+ assets[file] = compilation.assets[file] = new ConcatSource(
281
279
  new RawSource(source),
282
280
  currentSourceMappingURLComment
283
281
  .replace(/\[map\]/g, () => sourceMapString)