webpack 4.1.0 → 4.4.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.
Files changed (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,243 +1,245 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const asyncLib = require("neo-async");
8
- const path = require("path");
9
-
10
- const Tapable = require("tapable").Tapable;
11
- const AsyncSeriesWaterfallHook = require("tapable").AsyncSeriesWaterfallHook;
12
- const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
13
- const ContextModule = require("./ContextModule");
14
- const ContextElementDependency = require("./dependencies/ContextElementDependency");
15
-
16
- const EMPTY_RESOLVE_OPTIONS = {};
17
-
18
- module.exports = class ContextModuleFactory extends Tapable {
19
- constructor(resolverFactory) {
20
- super();
21
- this.hooks = {
22
- beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
23
- afterResolve: new AsyncSeriesWaterfallHook(["data"]),
24
- contextModuleFiles: new SyncWaterfallHook(["files"]),
25
- alternatives: new AsyncSeriesWaterfallHook(["modules"])
26
- };
27
- this._pluginCompat.tap("ContextModuleFactory", options => {
28
- switch (options.name) {
29
- case "before-resolve":
30
- case "after-resolve":
31
- case "alternatives":
32
- options.async = true;
33
- break;
34
- }
35
- });
36
- this.resolverFactory = resolverFactory;
37
- }
38
-
39
- create(data, callback) {
40
- const context = data.context;
41
- const dependencies = data.dependencies;
42
- const resolveOptions = data.resolveOptions;
43
- const dependency = dependencies[0];
44
- this.hooks.beforeResolve.callAsync(
45
- Object.assign(
46
- {
47
- context: context,
48
- dependencies: dependencies,
49
- resolveOptions
50
- },
51
- dependency.options
52
- ),
53
- (err, beforeResolveResult) => {
54
- if (err) return callback(err);
55
-
56
- // Ignored
57
- if (!beforeResolveResult) return callback();
58
-
59
- const context = beforeResolveResult.context;
60
- const request = beforeResolveResult.request;
61
- const resolveOptions = beforeResolveResult.resolveOptions;
62
-
63
- let loaders,
64
- resource,
65
- loadersPrefix = "";
66
- const idx = request.lastIndexOf("!");
67
- if (idx >= 0) {
68
- loaders = request.substr(0, idx + 1);
69
- let i;
70
- for (i = 0; i < loaders.length && loaders[i] === "!"; i++) {
71
- loadersPrefix += "!";
72
- }
73
- loaders = loaders
74
- .substr(i)
75
- .replace(/!+$/, "")
76
- .replace(/!!+/g, "!");
77
- if (loaders === "") loaders = [];
78
- else loaders = loaders.split("!");
79
- resource = request.substr(idx + 1);
80
- } else {
81
- loaders = [];
82
- resource = request;
83
- }
84
-
85
- const contextResolver = this.resolverFactory.get(
86
- "context",
87
- resolveOptions || EMPTY_RESOLVE_OPTIONS
88
- );
89
- const loaderResolver = this.resolverFactory.get(
90
- "loader",
91
- EMPTY_RESOLVE_OPTIONS
92
- );
93
-
94
- asyncLib.parallel(
95
- [
96
- callback => {
97
- contextResolver.resolve(
98
- {},
99
- context,
100
- resource,
101
- {},
102
- (err, result) => {
103
- if (err) return callback(err);
104
- callback(null, result);
105
- }
106
- );
107
- },
108
- callback => {
109
- asyncLib.map(
110
- loaders,
111
- (loader, callback) => {
112
- loaderResolver.resolve(
113
- {},
114
- context,
115
- loader,
116
- {},
117
- (err, result) => {
118
- if (err) return callback(err);
119
- callback(null, result);
120
- }
121
- );
122
- },
123
- callback
124
- );
125
- }
126
- ],
127
- (err, result) => {
128
- if (err) return callback(err);
129
-
130
- this.hooks.afterResolve.callAsync(
131
- Object.assign(
132
- {
133
- addon:
134
- loadersPrefix +
135
- result[1].join("!") +
136
- (result[1].length > 0 ? "!" : ""),
137
- resource: result[0],
138
- resolveDependencies: this.resolveDependencies.bind(this)
139
- },
140
- beforeResolveResult
141
- ),
142
- (err, result) => {
143
- if (err) return callback(err);
144
-
145
- // Ignored
146
- if (!result) return callback();
147
-
148
- return callback(
149
- null,
150
- new ContextModule(result.resolveDependencies, result)
151
- );
152
- }
153
- );
154
- }
155
- );
156
- }
157
- );
158
- }
159
-
160
- resolveDependencies(fs, options, callback) {
161
- const cmf = this;
162
- let resource = options.resource;
163
- let resourceQuery = options.resourceQuery;
164
- let recursive = options.recursive;
165
- let regExp = options.regExp;
166
- let include = options.include;
167
- let exclude = options.exclude;
168
- if (!regExp || !resource) return callback(null, []);
169
-
170
- const addDirectory = (directory, callback) => {
171
- fs.readdir(directory, (err, files) => {
172
- if (err) return callback(err);
173
- files = cmf.hooks.contextModuleFiles.call(files);
174
- if (!files || files.length === 0) return callback(null, []);
175
- asyncLib.map(
176
- files.filter(p => p.indexOf(".") !== 0),
177
- (segment, callback) => {
178
- const subResource = path.join(directory, segment);
179
-
180
- if (!exclude || !subResource.match(exclude)) {
181
- fs.stat(subResource, (err, stat) => {
182
- if (err) {
183
- if (err.code === "ENOENT") {
184
- // ENOENT is ok here because the file may have been deleted between
185
- // the readdir and stat calls.
186
- return callback();
187
- } else {
188
- return callback(err);
189
- }
190
- }
191
-
192
- if (stat.isDirectory()) {
193
- if (!recursive) return callback();
194
- addDirectory.call(this, subResource, callback);
195
- } else if (
196
- stat.isFile() &&
197
- (!include || subResource.match(include))
198
- ) {
199
- const obj = {
200
- context: resource,
201
- request:
202
- "." +
203
- subResource.substr(resource.length).replace(/\\/g, "/")
204
- };
205
-
206
- this.hooks.alternatives.callAsync(
207
- [obj],
208
- (err, alternatives) => {
209
- if (err) return callback(err);
210
- alternatives = alternatives
211
- .filter(obj => regExp.test(obj.request))
212
- .map(obj => {
213
- const dep = new ContextElementDependency(
214
- obj.request + resourceQuery,
215
- obj.request
216
- );
217
- dep.optional = true;
218
- return dep;
219
- });
220
- callback(null, alternatives);
221
- }
222
- );
223
- } else callback();
224
- });
225
- } else callback();
226
- },
227
- (err, result) => {
228
- if (err) return callback(err);
229
-
230
- if (!result) return callback(null, []);
231
-
232
- callback(
233
- null,
234
- result.filter(Boolean).reduce((a, i) => a.concat(i), [])
235
- );
236
- }
237
- );
238
- });
239
- };
240
-
241
- addDirectory(resource, callback);
242
- }
243
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const asyncLib = require("neo-async");
8
+ const path = require("path");
9
+
10
+ const {
11
+ Tapable,
12
+ AsyncSeriesWaterfallHook,
13
+ SyncWaterfallHook
14
+ } = require("tapable");
15
+ const ContextModule = require("./ContextModule");
16
+ const ContextElementDependency = require("./dependencies/ContextElementDependency");
17
+
18
+ const EMPTY_RESOLVE_OPTIONS = {};
19
+
20
+ module.exports = class ContextModuleFactory extends Tapable {
21
+ constructor(resolverFactory) {
22
+ super();
23
+ this.hooks = {
24
+ beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
25
+ afterResolve: new AsyncSeriesWaterfallHook(["data"]),
26
+ contextModuleFiles: new SyncWaterfallHook(["files"]),
27
+ alternatives: new AsyncSeriesWaterfallHook(["modules"])
28
+ };
29
+ this._pluginCompat.tap("ContextModuleFactory", options => {
30
+ switch (options.name) {
31
+ case "before-resolve":
32
+ case "after-resolve":
33
+ case "alternatives":
34
+ options.async = true;
35
+ break;
36
+ }
37
+ });
38
+ this.resolverFactory = resolverFactory;
39
+ }
40
+
41
+ create(data, callback) {
42
+ const context = data.context;
43
+ const dependencies = data.dependencies;
44
+ const resolveOptions = data.resolveOptions;
45
+ const dependency = dependencies[0];
46
+ this.hooks.beforeResolve.callAsync(
47
+ Object.assign(
48
+ {
49
+ context: context,
50
+ dependencies: dependencies,
51
+ resolveOptions
52
+ },
53
+ dependency.options
54
+ ),
55
+ (err, beforeResolveResult) => {
56
+ if (err) return callback(err);
57
+
58
+ // Ignored
59
+ if (!beforeResolveResult) return callback();
60
+
61
+ const context = beforeResolveResult.context;
62
+ const request = beforeResolveResult.request;
63
+ const resolveOptions = beforeResolveResult.resolveOptions;
64
+
65
+ let loaders,
66
+ resource,
67
+ loadersPrefix = "";
68
+ const idx = request.lastIndexOf("!");
69
+ if (idx >= 0) {
70
+ loaders = request.substr(0, idx + 1);
71
+ let i;
72
+ for (i = 0; i < loaders.length && loaders[i] === "!"; i++) {
73
+ loadersPrefix += "!";
74
+ }
75
+ loaders = loaders
76
+ .substr(i)
77
+ .replace(/!+$/, "")
78
+ .replace(/!!+/g, "!");
79
+ if (loaders === "") loaders = [];
80
+ else loaders = loaders.split("!");
81
+ resource = request.substr(idx + 1);
82
+ } else {
83
+ loaders = [];
84
+ resource = request;
85
+ }
86
+
87
+ const contextResolver = this.resolverFactory.get(
88
+ "context",
89
+ resolveOptions || EMPTY_RESOLVE_OPTIONS
90
+ );
91
+ const loaderResolver = this.resolverFactory.get(
92
+ "loader",
93
+ EMPTY_RESOLVE_OPTIONS
94
+ );
95
+
96
+ asyncLib.parallel(
97
+ [
98
+ callback => {
99
+ contextResolver.resolve(
100
+ {},
101
+ context,
102
+ resource,
103
+ {},
104
+ (err, result) => {
105
+ if (err) return callback(err);
106
+ callback(null, result);
107
+ }
108
+ );
109
+ },
110
+ callback => {
111
+ asyncLib.map(
112
+ loaders,
113
+ (loader, callback) => {
114
+ loaderResolver.resolve(
115
+ {},
116
+ context,
117
+ loader,
118
+ {},
119
+ (err, result) => {
120
+ if (err) return callback(err);
121
+ callback(null, result);
122
+ }
123
+ );
124
+ },
125
+ callback
126
+ );
127
+ }
128
+ ],
129
+ (err, result) => {
130
+ if (err) return callback(err);
131
+
132
+ this.hooks.afterResolve.callAsync(
133
+ Object.assign(
134
+ {
135
+ addon:
136
+ loadersPrefix +
137
+ result[1].join("!") +
138
+ (result[1].length > 0 ? "!" : ""),
139
+ resource: result[0],
140
+ resolveDependencies: this.resolveDependencies.bind(this)
141
+ },
142
+ beforeResolveResult
143
+ ),
144
+ (err, result) => {
145
+ if (err) return callback(err);
146
+
147
+ // Ignored
148
+ if (!result) return callback();
149
+
150
+ return callback(
151
+ null,
152
+ new ContextModule(result.resolveDependencies, result)
153
+ );
154
+ }
155
+ );
156
+ }
157
+ );
158
+ }
159
+ );
160
+ }
161
+
162
+ resolveDependencies(fs, options, callback) {
163
+ const cmf = this;
164
+ let resource = options.resource;
165
+ let resourceQuery = options.resourceQuery;
166
+ let recursive = options.recursive;
167
+ let regExp = options.regExp;
168
+ let include = options.include;
169
+ let exclude = options.exclude;
170
+ if (!regExp || !resource) return callback(null, []);
171
+
172
+ const addDirectory = (directory, callback) => {
173
+ fs.readdir(directory, (err, files) => {
174
+ if (err) return callback(err);
175
+ files = cmf.hooks.contextModuleFiles.call(files);
176
+ if (!files || files.length === 0) return callback(null, []);
177
+ asyncLib.map(
178
+ files.filter(p => p.indexOf(".") !== 0),
179
+ (segment, callback) => {
180
+ const subResource = path.join(directory, segment);
181
+
182
+ if (!exclude || !subResource.match(exclude)) {
183
+ fs.stat(subResource, (err, stat) => {
184
+ if (err) {
185
+ if (err.code === "ENOENT") {
186
+ // ENOENT is ok here because the file may have been deleted between
187
+ // the readdir and stat calls.
188
+ return callback();
189
+ } else {
190
+ return callback(err);
191
+ }
192
+ }
193
+
194
+ if (stat.isDirectory()) {
195
+ if (!recursive) return callback();
196
+ addDirectory.call(this, subResource, callback);
197
+ } else if (
198
+ stat.isFile() &&
199
+ (!include || subResource.match(include))
200
+ ) {
201
+ const obj = {
202
+ context: resource,
203
+ request:
204
+ "." +
205
+ subResource.substr(resource.length).replace(/\\/g, "/")
206
+ };
207
+
208
+ this.hooks.alternatives.callAsync(
209
+ [obj],
210
+ (err, alternatives) => {
211
+ if (err) return callback(err);
212
+ alternatives = alternatives
213
+ .filter(obj => regExp.test(obj.request))
214
+ .map(obj => {
215
+ const dep = new ContextElementDependency(
216
+ obj.request + resourceQuery,
217
+ obj.request
218
+ );
219
+ dep.optional = true;
220
+ return dep;
221
+ });
222
+ callback(null, alternatives);
223
+ }
224
+ );
225
+ } else callback();
226
+ });
227
+ } else callback();
228
+ },
229
+ (err, result) => {
230
+ if (err) return callback(err);
231
+
232
+ if (!result) return callback(null, []);
233
+
234
+ callback(
235
+ null,
236
+ result.filter(Boolean).reduce((a, i) => a.concat(i), [])
237
+ );
238
+ }
239
+ );
240
+ });
241
+ };
242
+
243
+ addDirectory(resource, callback);
244
+ }
245
+ };