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,142 +1,142 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const ContextDependencyHelpers = exports;
8
-
9
- /**
10
- * Escapes regular expression metacharacters
11
- * @param {string} str String to quote
12
- * @returns {string} Escaped string
13
- */
14
- const quotemeta = str => {
15
- return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
16
- };
17
-
18
- ContextDependencyHelpers.create = (
19
- Dep,
20
- range,
21
- param,
22
- expr,
23
- options,
24
- contextOptions
25
- ) => {
26
- let dep;
27
- let prefix;
28
- let postfix;
29
- let prefixRange;
30
- let valueRange;
31
- let idx;
32
- let context;
33
- let regExp;
34
- if (param.isTemplateString()) {
35
- prefix = param.quasis[0].string;
36
- postfix =
37
- param.quasis.length > 1
38
- ? param.quasis[param.quasis.length - 1].string
39
- : "";
40
- prefixRange = [param.quasis[0].range[0], param.quasis[0].range[1]];
41
- valueRange = param.range;
42
- idx = prefix.lastIndexOf("/");
43
- context = ".";
44
- if (idx >= 0) {
45
- context = prefix.substr(0, idx);
46
- prefix = `.${prefix.substr(idx)}`;
47
- }
48
- // If there are more than two quasis, maybe the generated RegExp can be more precise?
49
- regExp = new RegExp(
50
- `^${quotemeta(prefix)}${options.wrappedContextRegExp.source}${quotemeta(
51
- postfix
52
- )}$`
53
- );
54
- dep = new Dep(
55
- Object.assign(
56
- {
57
- request: context,
58
- recursive: options.wrappedContextRecursive,
59
- regExp,
60
- mode: "sync"
61
- },
62
- contextOptions
63
- ),
64
- range,
65
- valueRange
66
- );
67
- dep.loc = expr.loc;
68
- dep.replaces = [
69
- {
70
- range: prefixRange,
71
- value: prefix
72
- }
73
- ];
74
- dep.critical =
75
- options.wrappedContextCritical &&
76
- "a part of the request of a dependency is an expression";
77
- return dep;
78
- } else if (
79
- param.isWrapped() &&
80
- ((param.prefix && param.prefix.isString()) ||
81
- (param.postfix && param.postfix.isString()))
82
- ) {
83
- prefix = param.prefix && param.prefix.isString() ? param.prefix.string : "";
84
- postfix =
85
- param.postfix && param.postfix.isString() ? param.postfix.string : "";
86
- prefixRange =
87
- param.prefix && param.prefix.isString() ? param.prefix.range : null;
88
- valueRange = [
89
- prefixRange ? prefixRange[1] : param.range[0],
90
- param.range[1]
91
- ];
92
- idx = prefix.lastIndexOf("/");
93
- context = ".";
94
- if (idx >= 0) {
95
- context = prefix.substr(0, idx);
96
- prefix = `.${prefix.substr(idx)}`;
97
- }
98
- regExp = new RegExp(
99
- `^${quotemeta(prefix)}${options.wrappedContextRegExp.source}${quotemeta(
100
- postfix
101
- )}$`
102
- );
103
- dep = new Dep(
104
- Object.assign(
105
- {
106
- request: context,
107
- recursive: options.wrappedContextRecursive,
108
- regExp,
109
- mode: "sync"
110
- },
111
- contextOptions
112
- ),
113
- range,
114
- valueRange
115
- );
116
- dep.loc = expr.loc;
117
- dep.prepend = param.prefix && param.prefix.isString() ? prefix : null;
118
- dep.critical =
119
- options.wrappedContextCritical &&
120
- "a part of the request of a dependency is an expression";
121
- return dep;
122
- } else {
123
- dep = new Dep(
124
- Object.assign(
125
- {
126
- request: options.exprContextRequest,
127
- recursive: options.exprContextRecursive,
128
- regExp: options.exprContextRegExp,
129
- mode: "sync"
130
- },
131
- contextOptions
132
- ),
133
- range,
134
- param.range
135
- );
136
- dep.loc = expr.loc;
137
- dep.critical =
138
- options.exprContextCritical &&
139
- "the request of a dependency is an expression";
140
- return dep;
141
- }
142
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const ContextDependencyHelpers = exports;
8
+
9
+ /**
10
+ * Escapes regular expression metacharacters
11
+ * @param {string} str String to quote
12
+ * @returns {string} Escaped string
13
+ */
14
+ const quotemeta = str => {
15
+ return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
16
+ };
17
+
18
+ ContextDependencyHelpers.create = (
19
+ Dep,
20
+ range,
21
+ param,
22
+ expr,
23
+ options,
24
+ contextOptions
25
+ ) => {
26
+ let dep;
27
+ let prefix;
28
+ let postfix;
29
+ let prefixRange;
30
+ let valueRange;
31
+ let idx;
32
+ let context;
33
+ let regExp;
34
+ if (param.isTemplateString()) {
35
+ prefix = param.quasis[0].string;
36
+ postfix =
37
+ param.quasis.length > 1
38
+ ? param.quasis[param.quasis.length - 1].string
39
+ : "";
40
+ prefixRange = [param.quasis[0].range[0], param.quasis[0].range[1]];
41
+ valueRange = param.range;
42
+ idx = prefix.lastIndexOf("/");
43
+ context = ".";
44
+ if (idx >= 0) {
45
+ context = prefix.substr(0, idx);
46
+ prefix = `.${prefix.substr(idx)}`;
47
+ }
48
+ // If there are more than two quasis, maybe the generated RegExp can be more precise?
49
+ regExp = new RegExp(
50
+ `^${quotemeta(prefix)}${options.wrappedContextRegExp.source}${quotemeta(
51
+ postfix
52
+ )}$`
53
+ );
54
+ dep = new Dep(
55
+ Object.assign(
56
+ {
57
+ request: context,
58
+ recursive: options.wrappedContextRecursive,
59
+ regExp,
60
+ mode: "sync"
61
+ },
62
+ contextOptions
63
+ ),
64
+ range,
65
+ valueRange
66
+ );
67
+ dep.loc = expr.loc;
68
+ dep.replaces = [
69
+ {
70
+ range: prefixRange,
71
+ value: prefix
72
+ }
73
+ ];
74
+ dep.critical =
75
+ options.wrappedContextCritical &&
76
+ "a part of the request of a dependency is an expression";
77
+ return dep;
78
+ } else if (
79
+ param.isWrapped() &&
80
+ ((param.prefix && param.prefix.isString()) ||
81
+ (param.postfix && param.postfix.isString()))
82
+ ) {
83
+ prefix = param.prefix && param.prefix.isString() ? param.prefix.string : "";
84
+ postfix =
85
+ param.postfix && param.postfix.isString() ? param.postfix.string : "";
86
+ prefixRange =
87
+ param.prefix && param.prefix.isString() ? param.prefix.range : null;
88
+ valueRange = [
89
+ prefixRange ? prefixRange[1] : param.range[0],
90
+ param.range[1]
91
+ ];
92
+ idx = prefix.lastIndexOf("/");
93
+ context = ".";
94
+ if (idx >= 0) {
95
+ context = prefix.substr(0, idx);
96
+ prefix = `.${prefix.substr(idx)}`;
97
+ }
98
+ regExp = new RegExp(
99
+ `^${quotemeta(prefix)}${options.wrappedContextRegExp.source}${quotemeta(
100
+ postfix
101
+ )}$`
102
+ );
103
+ dep = new Dep(
104
+ Object.assign(
105
+ {
106
+ request: context,
107
+ recursive: options.wrappedContextRecursive,
108
+ regExp,
109
+ mode: "sync"
110
+ },
111
+ contextOptions
112
+ ),
113
+ range,
114
+ valueRange
115
+ );
116
+ dep.loc = expr.loc;
117
+ dep.prepend = param.prefix && param.prefix.isString() ? prefix : null;
118
+ dep.critical =
119
+ options.wrappedContextCritical &&
120
+ "a part of the request of a dependency is an expression";
121
+ return dep;
122
+ } else {
123
+ dep = new Dep(
124
+ Object.assign(
125
+ {
126
+ request: options.exprContextRequest,
127
+ recursive: options.exprContextRecursive,
128
+ regExp: options.exprContextRegExp,
129
+ mode: "sync"
130
+ },
131
+ contextOptions
132
+ ),
133
+ range,
134
+ param.range
135
+ );
136
+ dep.loc = expr.loc;
137
+ dep.critical =
138
+ options.exprContextCritical &&
139
+ "the request of a dependency is an expression";
140
+ return dep;
141
+ }
142
+ };
@@ -10,11 +10,11 @@ exports.module = request =>
10
10
  `!(function webpackMissingModule() { ${exports.moduleCode(request)} }())`;
11
11
 
12
12
  exports.promise = request => {
13
- const errorCode = toErrorCode(`Cannot find module "${request}"`);
13
+ const errorCode = toErrorCode(`Cannot find module '${request}'`);
14
14
  return `Promise.reject(function webpackMissingModule() { ${errorCode} return e; }())`;
15
15
  };
16
16
 
17
17
  exports.moduleCode = request => {
18
- const errorCode = toErrorCode(`Cannot find module "${request}"`);
18
+ const errorCode = toErrorCode(`Cannot find module '${request}'`);
19
19
  return `${errorCode} throw e;`;
20
20
  };
@@ -1,40 +1,42 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- class RemoveEmptyChunksPlugin {
8
- apply(compiler) {
9
- compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => {
10
- const handler = chunks => {
11
- chunks
12
- .filter(
13
- chunk =>
14
- chunk.isEmpty() && !chunk.hasRuntime() && !chunk.hasEntryModule()
15
- )
16
- .forEach(chunk => {
17
- chunk.remove("empty");
18
- chunks.splice(chunks.indexOf(chunk), 1);
19
- });
20
- };
21
- compilation.hooks.optimizeChunksBasic.tap(
22
- "RemoveEmptyChunksPlugin",
23
- handler
24
- );
25
- compilation.hooks.optimizeChunksAdvanced.tap(
26
- "RemoveEmptyChunksPlugin",
27
- handler
28
- );
29
- compilation.hooks.optimizeExtractedChunksBasic.tap(
30
- "RemoveEmptyChunksPlugin",
31
- handler
32
- );
33
- compilation.hooks.optimizeExtractedChunksAdvanced.tap(
34
- "RemoveEmptyChunksPlugin",
35
- handler
36
- );
37
- });
38
- }
39
- }
40
- module.exports = RemoveEmptyChunksPlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ class RemoveEmptyChunksPlugin {
8
+ apply(compiler) {
9
+ compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => {
10
+ const handler = chunks => {
11
+ for (let i = chunks.length - 1; i >= 0; i--) {
12
+ const chunk = chunks[i];
13
+ if (
14
+ chunk.isEmpty() &&
15
+ !chunk.hasRuntime() &&
16
+ !chunk.hasEntryModule()
17
+ ) {
18
+ chunk.remove("empty");
19
+ chunks.splice(i, 1);
20
+ }
21
+ }
22
+ };
23
+ compilation.hooks.optimizeChunksBasic.tap(
24
+ "RemoveEmptyChunksPlugin",
25
+ handler
26
+ );
27
+ compilation.hooks.optimizeChunksAdvanced.tap(
28
+ "RemoveEmptyChunksPlugin",
29
+ handler
30
+ );
31
+ compilation.hooks.optimizeExtractedChunksBasic.tap(
32
+ "RemoveEmptyChunksPlugin",
33
+ handler
34
+ );
35
+ compilation.hooks.optimizeExtractedChunksAdvanced.tap(
36
+ "RemoveEmptyChunksPlugin",
37
+ handler
38
+ );
39
+ });
40
+ }
41
+ }
42
+ module.exports = RemoveEmptyChunksPlugin;
@@ -19,11 +19,15 @@ module.exports = class RuntimeChunkPlugin {
19
19
  compilation.hooks.optimizeChunksAdvanced.tap("RuntimeChunkPlugin", () => {
20
20
  for (const entrypoint of compilation.entrypoints.values()) {
21
21
  const chunk = entrypoint.getRuntimeChunk();
22
- if (chunk.getNumberOfModules() > 0) {
23
- let name = this.options.name;
24
- if (typeof name === "function") {
25
- name = name(entrypoint);
26
- }
22
+ let name = this.options.name;
23
+ if (typeof name === "function") {
24
+ name = name(entrypoint);
25
+ }
26
+ if (
27
+ chunk.getNumberOfModules() > 0 ||
28
+ !chunk.preventIntegration ||
29
+ chunk.name !== name
30
+ ) {
27
31
  const newChunk = compilation.addChunk(name);
28
32
  newChunk.preventIntegration = true;
29
33
  entrypoint.unshiftChunk(newChunk);