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
@@ -7,22 +7,59 @@
7
7
  const { ConcatSource, OriginalSource } = require("webpack-sources");
8
8
  const Template = require("./Template");
9
9
 
10
- function accessorToObjectAccess(accessor) {
10
+ /** @typedef {import("./Compilation")} Compilation */
11
+
12
+ /**
13
+ * @param {string[]} accessor the accessor to convert to path
14
+ * @returns {string} the path
15
+ */
16
+ const accessorToObjectAccess = accessor => {
11
17
  return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
12
- }
18
+ };
13
19
 
14
- function accessorAccess(base, accessor) {
15
- accessor = [].concat(accessor);
16
- return accessor
17
- .map((a, idx) => {
18
- a = base + accessorToObjectAccess(accessor.slice(0, idx + 1));
19
- if (idx === accessor.length - 1) return a;
20
+ /**
21
+ * @param {string=} base the path prefix
22
+ * @param {string|string[]} accessor the accessor
23
+ * @param {string=} joinWith the element separator
24
+ * @returns {string} the path
25
+ */
26
+ const accessorAccess = (base, accessor, joinWith = ", ") => {
27
+ const accessors = Array.isArray(accessor) ? accessor : [accessor];
28
+ return accessors
29
+ .map((_, idx) => {
30
+ const a = base
31
+ ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
32
+ : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
33
+ if (idx === accessors.length - 1) return a;
34
+ if (idx === 0 && typeof base === "undefined")
35
+ return `${a} = typeof ${a} === "object" ? ${a} : {}`;
20
36
  return `${a} = ${a} || {}`;
21
37
  })
22
- .join(", ");
23
- }
38
+ .join(joinWith);
39
+ };
40
+
41
+ /** @typedef {string | string[] | Record<string, string | string[]>} UmdMainTemplatePluginName */
42
+
43
+ /**
44
+ * @typedef {Object} AuxiliaryCommentObject
45
+ * @property {string} root
46
+ * @property {string} commonjs
47
+ * @property {string} commonjs2
48
+ * @property {string} amd
49
+ */
50
+
51
+ /**
52
+ * @typedef {Object} UmdMainTemplatePluginOption
53
+ * @property {boolean=} optionalAmdExternalAsGlobal
54
+ * @property {boolean} namedDefine
55
+ * @property {string | AuxiliaryCommentObject} auxiliaryComment
56
+ */
24
57
 
25
58
  class UmdMainTemplatePlugin {
59
+ /**
60
+ * @param {UmdMainTemplatePluginName} name the name of the UMD library
61
+ * @param {UmdMainTemplatePluginOption} options the plugin option
62
+ */
26
63
  constructor(name, options) {
27
64
  if (typeof name === "object" && !Array.isArray(name)) {
28
65
  this.name = name.root || name.amd || name.commonjs;
@@ -40,6 +77,10 @@ class UmdMainTemplatePlugin {
40
77
  this.auxiliaryComment = options.auxiliaryComment;
41
78
  }
42
79
 
80
+ /**
81
+ * @param {Compilation} compilation the compilation instance
82
+ * @returns {void}
83
+ */
43
84
  apply(compilation) {
44
85
  const { mainTemplate, chunkTemplate, runtimeTemplate } = compilation;
45
86
 
@@ -152,23 +193,27 @@ class UmdMainTemplatePlugin {
152
193
  amdFactory = "factory";
153
194
  }
154
195
 
196
+ const auxiliaryComment = this.auxiliaryComment;
197
+
198
+ const getAuxilaryComment = type => {
199
+ if (auxiliaryComment) {
200
+ if (typeof auxiliaryComment === "string")
201
+ return "\t//" + auxiliaryComment + "\n";
202
+ if (auxiliaryComment[type])
203
+ return "\t//" + auxiliaryComment[type] + "\n";
204
+ }
205
+ return "";
206
+ };
207
+
155
208
  return new ConcatSource(
156
209
  new OriginalSource(
157
210
  "(function webpackUniversalModuleDefinition(root, factory) {\n" +
158
- (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
159
- ? " //" + this.auxiliaryComment + "\n"
160
- : this.auxiliaryComment.commonjs2
161
- ? " //" + this.auxiliaryComment.commonjs2 + "\n"
162
- : "") +
211
+ getAuxilaryComment("commonjs2") +
163
212
  " if(typeof exports === 'object' && typeof module === 'object')\n" +
164
213
  " module.exports = factory(" +
165
214
  externalsRequireArray("commonjs2") +
166
215
  ");\n" +
167
- (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
168
- ? " //" + this.auxiliaryComment + "\n"
169
- : this.auxiliaryComment.amd
170
- ? " //" + this.auxiliaryComment.amd + "\n"
171
- : "") +
216
+ getAuxilaryComment("amd") +
172
217
  " else if(typeof define === 'function' && define.amd)\n" +
173
218
  (requiredExternals.length > 0
174
219
  ? this.names.amd && this.namedDefine === true
@@ -192,24 +237,14 @@ class UmdMainTemplatePlugin {
192
237
  ");\n"
193
238
  : " define([], " + amdFactory + ");\n") +
194
239
  (this.names.root || this.names.commonjs
195
- ? (this.auxiliaryComment &&
196
- typeof this.auxiliaryComment === "string"
197
- ? " //" + this.auxiliaryComment + "\n"
198
- : this.auxiliaryComment.commonjs
199
- ? " //" + this.auxiliaryComment.commonjs + "\n"
200
- : "") +
240
+ ? getAuxilaryComment("commonjs") +
201
241
  " else if(typeof exports === 'object')\n" +
202
242
  " exports[" +
203
243
  libraryName(this.names.commonjs || this.names.root) +
204
244
  "] = factory(" +
205
245
  externalsRequireArray("commonjs") +
206
246
  ");\n" +
207
- (this.auxiliaryComment &&
208
- typeof this.auxiliaryComment === "string"
209
- ? " //" + this.auxiliaryComment + "\n"
210
- : this.auxiliaryComment.root
211
- ? " //" + this.auxiliaryComment.root + "\n"
212
- : "") +
247
+ getAuxilaryComment("root") +
213
248
  " else\n" +
214
249
  " " +
215
250
  replaceKeys(
@@ -4,7 +4,11 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- module.exports = class WebpackError extends Error {
7
+ class WebpackError extends Error {
8
+ /**
9
+ * Creates an instance of WebpackError.
10
+ * @param {string=} message error message
11
+ */
8
12
  constructor(message) {
9
13
  super(message);
10
14
 
@@ -16,4 +20,6 @@ module.exports = class WebpackError extends Error {
16
20
  inspect() {
17
21
  return this.stack + (this.details ? `\n${this.details}` : "");
18
22
  }
19
- };
23
+ }
24
+
25
+ module.exports = WebpackError;
@@ -3,6 +3,26 @@
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
5
  "use strict";
6
+
7
+ /**
8
+ * @typedef {Object} LineAndColumn
9
+ * @property {number=} line
10
+ * @property {number=} column
11
+ */
12
+
13
+ /**
14
+ * @typedef {Object} NodeLocation
15
+ * @property {LineAndColumn=} start
16
+ * @property {LineAndColumn=} end
17
+ * @property {number=} index
18
+ */
19
+
20
+ /**
21
+ * Compare two locations
22
+ * @param {string|NodeLocation} a A location node
23
+ * @param {string|NodeLocation} b A location node
24
+ * @returns {-1|0|1} sorting comparator value
25
+ */
6
26
  module.exports = (a, b) => {
7
27
  if (typeof a === "string") {
8
28
  if (typeof b === "string") {