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
@@ -1,101 +1,115 @@
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 { ConcatSource } = require("webpack-sources");
9
- const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
- const Template = require("./Template");
11
-
12
- const validateOptions = require("schema-utils");
13
- const schema = require("../schemas/plugins/BannerPlugin.json");
14
-
15
- const wrapComment = str => {
16
- if (!str.includes("\n")) return Template.toComment(str);
17
- return `/*!\n * ${str
18
- .replace(/\*\//g, "* /")
19
- .split("\n")
20
- .join("\n * ")}\n */`;
21
- };
22
-
23
- class BannerPlugin {
24
- constructor(options) {
25
- if (arguments.length > 1)
26
- throw new Error(
27
- "BannerPlugin only takes one argument (pass an options object)"
28
- );
29
-
30
- validateOptions(schema, options, "Banner Plugin");
31
-
32
- if (typeof options === "string")
33
- options = {
34
- banner: options
35
- };
36
- this.options = options || {};
37
- this.banner = this.options.raw
38
- ? options.banner
39
- : wrapComment(options.banner);
40
- }
41
-
42
- apply(compiler) {
43
- const options = this.options;
44
- const banner = this.banner;
45
- const matchObject = ModuleFilenameHelpers.matchObject.bind(
46
- undefined,
47
- options
48
- );
49
-
50
- compiler.hooks.compilation.tap("BannerPlugin", compilation => {
51
- compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", chunks => {
52
- for (const chunk of chunks) {
53
- if (options.entryOnly && !chunk.canBeInitial()) {
54
- continue;
55
- }
56
-
57
- for (const file of chunk.files) {
58
- if (!matchObject(file)) {
59
- continue;
60
- }
61
-
62
- let basename;
63
- let query = "";
64
- let filename = file;
65
- const hash = compilation.hash;
66
- const querySplit = filename.indexOf("?");
67
-
68
- if (querySplit >= 0) {
69
- query = filename.substr(querySplit);
70
- filename = filename.substr(0, querySplit);
71
- }
72
-
73
- const lastSlashIndex = filename.lastIndexOf("/");
74
-
75
- if (lastSlashIndex === -1) {
76
- basename = filename;
77
- } else {
78
- basename = filename.substr(lastSlashIndex + 1);
79
- }
80
-
81
- const comment = compilation.getPath(banner, {
82
- hash,
83
- chunk,
84
- filename,
85
- basename,
86
- query
87
- });
88
-
89
- compilation.assets[file] = new ConcatSource(
90
- comment,
91
- "\n",
92
- compilation.assets[file]
93
- );
94
- }
95
- }
96
- });
97
- });
98
- }
99
- }
100
-
101
- module.exports = BannerPlugin;
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 { ConcatSource } = require("webpack-sources");
9
+ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
+ const Template = require("./Template");
11
+
12
+ const validateOptions = require("schema-utils");
13
+ const schema = require("../schemas/plugins/BannerPlugin.json");
14
+
15
+ const wrapComment = str => {
16
+ if (!str.includes("\n")) return Template.toComment(str);
17
+ return `/*!\n * ${str
18
+ .replace(/\*\//g, "* /")
19
+ .split("\n")
20
+ .join("\n * ")}\n */`;
21
+ };
22
+
23
+ class BannerPlugin {
24
+ constructor(options) {
25
+ if (arguments.length > 1) {
26
+ throw new Error(
27
+ "BannerPlugin only takes one argument (pass an options object)"
28
+ );
29
+ }
30
+
31
+ validateOptions(schema, options, "Banner Plugin");
32
+
33
+ if (typeof options === "string" || typeof options === "function") {
34
+ options = {
35
+ banner: options
36
+ };
37
+ }
38
+
39
+ this.options = options || {};
40
+
41
+ if (typeof options.banner === "function") {
42
+ const getBanner = this.options.banner;
43
+ this.banner = this.options.raw
44
+ ? getBanner
45
+ : data => wrapComment(getBanner(data));
46
+ } else {
47
+ const banner = this.options.raw
48
+ ? this.options.banner
49
+ : wrapComment(this.options.banner);
50
+ this.banner = () => banner;
51
+ }
52
+ }
53
+
54
+ apply(compiler) {
55
+ const options = this.options;
56
+ const banner = this.banner;
57
+ const matchObject = ModuleFilenameHelpers.matchObject.bind(
58
+ undefined,
59
+ options
60
+ );
61
+
62
+ compiler.hooks.compilation.tap("BannerPlugin", compilation => {
63
+ compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", chunks => {
64
+ for (const chunk of chunks) {
65
+ if (options.entryOnly && !chunk.canBeInitial()) {
66
+ continue;
67
+ }
68
+
69
+ for (const file of chunk.files) {
70
+ if (!matchObject(file)) {
71
+ continue;
72
+ }
73
+
74
+ let basename;
75
+ let query = "";
76
+ let filename = file;
77
+ const hash = compilation.hash;
78
+ const querySplit = filename.indexOf("?");
79
+
80
+ if (querySplit >= 0) {
81
+ query = filename.substr(querySplit);
82
+ filename = filename.substr(0, querySplit);
83
+ }
84
+
85
+ const lastSlashIndex = filename.lastIndexOf("/");
86
+
87
+ if (lastSlashIndex === -1) {
88
+ basename = filename;
89
+ } else {
90
+ basename = filename.substr(lastSlashIndex + 1);
91
+ }
92
+
93
+ const data = {
94
+ hash,
95
+ chunk,
96
+ filename,
97
+ basename,
98
+ query
99
+ };
100
+
101
+ const comment = compilation.getPath(banner(data), data);
102
+
103
+ compilation.assets[file] = new ConcatSource(
104
+ comment,
105
+ "\n",
106
+ compilation.assets[file]
107
+ );
108
+ }
109
+ }
110
+ });
111
+ });
112
+ }
113
+ }
114
+
115
+ module.exports = BannerPlugin;
@@ -6,7 +6,13 @@
6
6
 
7
7
  const WebpackError = require("./WebpackError");
8
8
 
9
- module.exports = class CaseSensitiveModulesWarning extends WebpackError {
9
+ /** @typedef {import("./Module")} Module */
10
+
11
+ class CaseSensitiveModulesWarning extends WebpackError {
12
+ /**
13
+ * Creates an instance of CaseSensitiveModulesWarning.
14
+ * @param {Module[]} modules modules that were detected
15
+ */
10
16
  constructor(modules) {
11
17
  super();
12
18
 
@@ -23,6 +29,11 @@ ${modulesList}`;
23
29
  Error.captureStackTrace(this, this.constructor);
24
30
  }
25
31
 
32
+ /**
33
+ * @private
34
+ * @param {Module[]} modules the modules to be sorted
35
+ * @returns {Module[]} sorted version of original modules
36
+ */
26
37
  _sort(modules) {
27
38
  return modules.slice().sort((a, b) => {
28
39
  a = a.identifier();
@@ -36,6 +47,11 @@ ${modulesList}`;
36
47
  });
37
48
  }
38
49
 
50
+ /**
51
+ * @private
52
+ * @param {Module[]} modules each module from throw
53
+ * @returns {string} each message from provided moduels
54
+ */
39
55
  _moduleMessages(modules) {
40
56
  return modules
41
57
  .map(m => {
@@ -50,4 +66,6 @@ ${modulesList}`;
50
66
  })
51
67
  .join("\n");
52
68
  }
53
- };
69
+ }
70
+
71
+ module.exports = CaseSensitiveModulesWarning;
package/lib/Chunk.js CHANGED
@@ -128,6 +128,7 @@ class Chunk {
128
128
  this.chunkReason = undefined;
129
129
  /** @type {boolean} */
130
130
  this.extraAsync = false;
131
+ this.removedModules = undefined;
131
132
  }
132
133
 
133
134
  /**