webpack 4.10.1 → 4.10.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.
- package/lib/AmdMainTemplatePlugin.js +3 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/Chunk.js +44 -16
- package/lib/ChunkGroup.js +13 -5
- package/lib/Compilation.js +70 -28
- package/lib/Compiler.js +22 -10
- package/lib/ConstPlugin.js +25 -9
- package/lib/ContextModule.js +88 -36
- package/lib/ContextModuleFactory.js +18 -7
- package/lib/ContextReplacementPlugin.js +14 -7
- package/lib/DefinePlugin.js +15 -6
- package/lib/DependenciesBlock.js +3 -1
- package/lib/DependenciesBlockVariable.js +2 -1
- package/lib/DllPlugin.js +4 -2
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/ErrorHelpers.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/FlagDependencyUsagePlugin.js +11 -5
- package/lib/FunctionModuleTemplatePlugin.js +8 -6
- package/lib/HotModuleReplacement.runtime.js +7 -3
- package/lib/HotModuleReplacementPlugin.js +13 -6
- package/lib/JavascriptGenerator.js +2 -1
- package/lib/JavascriptModulesPlugin.js +4 -9
- package/lib/JsonParser.js +2 -1
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -1
- package/lib/Module.js +9 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +11 -4
- package/lib/NormalModuleFactory.js +30 -12
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +137 -59
- package/lib/ParserHelpers.js +5 -2
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +11 -7
- package/lib/RequestShortener.js +13 -6
- package/lib/RuleSet.js +39 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +64 -28
- package/lib/Template.js +4 -2
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +32 -16
- package/lib/WebpackOptionsDefaulter.js +7 -4
- package/lib/WebpackOptionsValidationError.js +48 -19
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +6 -3
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +12 -7
- package/lib/dependencies/LocalModulesHelpers.js +13 -6
- package/lib/dependencies/RequireContextPlugin.js +4 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
- package/lib/formatLocation.js +15 -7
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +6 -3
- package/lib/node/NodeSourcePlugin.js +9 -5
- package/lib/node/NodeWatchFileSystem.js +29 -12
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
- package/lib/optimize/ConcatenatedModule.js +19 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
- package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
- package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/WasmMainTemplatePlugin.js +4 -2
- package/lib/wasm/WebAssemblyGenerator.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +2 -1
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +9 -9
package/lib/Module.js
CHANGED
@@ -225,8 +225,9 @@ class Module extends DependenciesBlock {
|
|
225
225
|
|
226
226
|
hasReasonForChunk(chunk) {
|
227
227
|
if (this._rewriteChunkInReasons) {
|
228
|
-
for (const operation of this._rewriteChunkInReasons)
|
228
|
+
for (const operation of this._rewriteChunkInReasons) {
|
229
229
|
this._doRewriteChunkInReasons(operation.oldChunk, operation.newChunks);
|
230
|
+
}
|
230
231
|
this._rewriteChunkInReasons = undefined;
|
231
232
|
}
|
232
233
|
for (let i = 0; i < this.reasons.length; i++) {
|
@@ -241,8 +242,9 @@ class Module extends DependenciesBlock {
|
|
241
242
|
|
242
243
|
rewriteChunkInReasons(oldChunk, newChunks) {
|
243
244
|
// This is expensive. Delay operation until we really need the data
|
244
|
-
if (this._rewriteChunkInReasons === undefined)
|
245
|
+
if (this._rewriteChunkInReasons === undefined) {
|
245
246
|
this._rewriteChunkInReasons = [];
|
247
|
+
}
|
246
248
|
this._rewriteChunkInReasons.push({
|
247
249
|
oldChunk,
|
248
250
|
newChunks
|
@@ -266,13 +268,15 @@ class Module extends DependenciesBlock {
|
|
266
268
|
|
267
269
|
// Mangle export name if possible
|
268
270
|
if (this.isProvided(exportName)) {
|
269
|
-
if (this.buildMeta.exportsType === "namespace")
|
271
|
+
if (this.buildMeta.exportsType === "namespace") {
|
270
272
|
return Template.numberToIdentifer(idx);
|
271
|
-
|
273
|
+
}
|
274
|
+
if (
|
272
275
|
this.buildMeta.exportsType === "named" &&
|
273
276
|
!this.usedExports.includes("default")
|
274
|
-
)
|
277
|
+
) {
|
275
278
|
return Template.numberToIdentifer(idx);
|
279
|
+
}
|
276
280
|
}
|
277
281
|
return exportName;
|
278
282
|
}
|
@@ -48,8 +48,9 @@ const getHash = str => {
|
|
48
48
|
};
|
49
49
|
|
50
50
|
const asRegExp = test => {
|
51
|
-
if (typeof test === "string")
|
51
|
+
if (typeof test === "string") {
|
52
52
|
test = new RegExp("^" + test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
53
|
+
}
|
53
54
|
return test;
|
54
55
|
};
|
55
56
|
|
@@ -141,7 +142,9 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
|
|
141
142
|
if (countMap[item].length > 1) {
|
142
143
|
if (comparator && countMap[item][0] === i) return item;
|
143
144
|
return fn(item, i, posMap[item]++);
|
144
|
-
} else
|
145
|
+
} else {
|
146
|
+
return item;
|
147
|
+
}
|
145
148
|
});
|
146
149
|
};
|
147
150
|
|
@@ -156,11 +159,20 @@ ModuleFilenameHelpers.matchPart = (str, test) => {
|
|
156
159
|
};
|
157
160
|
|
158
161
|
ModuleFilenameHelpers.matchObject = (obj, str) => {
|
159
|
-
if (obj.test)
|
160
|
-
if (!ModuleFilenameHelpers.matchPart(str, obj.test))
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
if (obj.test) {
|
163
|
+
if (!ModuleFilenameHelpers.matchPart(str, obj.test)) {
|
164
|
+
return false;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
if (obj.include) {
|
168
|
+
if (!ModuleFilenameHelpers.matchPart(str, obj.include)) {
|
169
|
+
return false;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
if (obj.exclude) {
|
173
|
+
if (ModuleFilenameHelpers.matchPart(str, obj.exclude)) {
|
174
|
+
return false;
|
175
|
+
}
|
176
|
+
}
|
165
177
|
return true;
|
166
178
|
};
|
package/lib/MultiCompiler.js
CHANGED
@@ -162,8 +162,11 @@ module.exports = class MultiCompiler extends Tapable {
|
|
162
162
|
for (const c of list) {
|
163
163
|
const ready =
|
164
164
|
!c.dependencies || c.dependencies.every(isDependencyFulfilled);
|
165
|
-
if (ready)
|
166
|
-
|
165
|
+
if (ready) {
|
166
|
+
readyCompilers.push(c);
|
167
|
+
} else {
|
168
|
+
remainingCompilers.push(c);
|
169
|
+
}
|
167
170
|
}
|
168
171
|
return readyCompilers;
|
169
172
|
};
|
@@ -233,12 +236,16 @@ module.exports = class MultiCompiler extends Tapable {
|
|
233
236
|
}
|
234
237
|
|
235
238
|
run(callback) {
|
236
|
-
if (this.running)
|
239
|
+
if (this.running) {
|
240
|
+
return callback(new ConcurrentCompilationError());
|
241
|
+
}
|
237
242
|
|
238
243
|
const finalCallback = (err, stats) => {
|
239
244
|
this.running = false;
|
240
245
|
|
241
|
-
if (callback !== undefined)
|
246
|
+
if (callback !== undefined) {
|
247
|
+
return callback(err, stats);
|
248
|
+
}
|
242
249
|
};
|
243
250
|
|
244
251
|
const allStats = this.compilers.map(() => null);
|
@@ -249,13 +256,17 @@ module.exports = class MultiCompiler extends Tapable {
|
|
249
256
|
(compiler, callback) => {
|
250
257
|
const compilerIdx = this.compilers.indexOf(compiler);
|
251
258
|
compiler.run((err, stats) => {
|
252
|
-
if (err)
|
259
|
+
if (err) {
|
260
|
+
return callback(err);
|
261
|
+
}
|
253
262
|
allStats[compilerIdx] = stats;
|
254
263
|
callback();
|
255
264
|
});
|
256
265
|
},
|
257
266
|
err => {
|
258
|
-
if (err)
|
267
|
+
if (err) {
|
268
|
+
return finalCallback(err);
|
269
|
+
}
|
259
270
|
finalCallback(null, new MultiStats(allStats));
|
260
271
|
}
|
261
272
|
);
|
@@ -264,8 +275,9 @@ module.exports = class MultiCompiler extends Tapable {
|
|
264
275
|
|
265
276
|
purgeInputFileSystem() {
|
266
277
|
for (const compiler of this.compilers) {
|
267
|
-
if (compiler.inputFileSystem && compiler.inputFileSystem.purge)
|
278
|
+
if (compiler.inputFileSystem && compiler.inputFileSystem.purge) {
|
268
279
|
compiler.inputFileSystem.purge();
|
280
|
+
}
|
269
281
|
}
|
270
282
|
}
|
271
283
|
};
|
package/lib/MultiModule.js
CHANGED
@@ -56,10 +56,13 @@ class MultiModule extends Module {
|
|
56
56
|
let idx = 0;
|
57
57
|
for (const dep of this.dependencies) {
|
58
58
|
if (dep.module) {
|
59
|
-
if (idx === this.dependencies.length - 1)
|
59
|
+
if (idx === this.dependencies.length - 1) {
|
60
|
+
str.push("module.exports = ");
|
61
|
+
}
|
60
62
|
str.push("__webpack_require__(");
|
61
|
-
if (runtimeTemplate.outputOptions.pathinfo)
|
63
|
+
if (runtimeTemplate.outputOptions.pathinfo) {
|
62
64
|
str.push(Template.toComment(dep.request));
|
65
|
+
}
|
63
66
|
str.push(`${JSON.stringify(dep.module.id)}`);
|
64
67
|
str.push(")");
|
65
68
|
} else {
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -30,8 +30,9 @@ class NodeStuffPlugin {
|
|
30
30
|
if (parserOptions.node === false) return;
|
31
31
|
|
32
32
|
let localOptions = options;
|
33
|
-
if (parserOptions.node)
|
33
|
+
if (parserOptions.node) {
|
34
34
|
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
35
|
+
}
|
35
36
|
|
36
37
|
const setConstant = (expressionName, value) => {
|
37
38
|
parser.hooks.expression
|
package/lib/NormalModule.js
CHANGED
@@ -153,12 +153,15 @@ class NormalModule extends Module {
|
|
153
153
|
const loaderContext = {
|
154
154
|
version: 2,
|
155
155
|
emitWarning: warning => {
|
156
|
-
if (!(warning instanceof Error))
|
156
|
+
if (!(warning instanceof Error)) {
|
157
157
|
warning = new NonErrorEmittedError(warning);
|
158
|
+
}
|
158
159
|
this.warnings.push(new ModuleWarning(this, warning));
|
159
160
|
},
|
160
161
|
emitError: error => {
|
161
|
-
if (!(error instanceof Error))
|
162
|
+
if (!(error instanceof Error)) {
|
163
|
+
error = new NonErrorEmittedError(error);
|
164
|
+
}
|
162
165
|
this.errors.push(new ModuleError(this, error));
|
163
166
|
},
|
164
167
|
exec: (code, filename) => {
|
@@ -174,7 +177,9 @@ class NormalModule extends Module {
|
|
174
177
|
resolver.resolve({}, context, request, {}, callback);
|
175
178
|
},
|
176
179
|
emitFile: (name, content, sourceMap) => {
|
177
|
-
if (!this.buildInfo.assets)
|
180
|
+
if (!this.buildInfo.assets) {
|
181
|
+
this.buildInfo.assets = Object.create(null);
|
182
|
+
}
|
178
183
|
this.buildInfo.assets[name] = this.createSourceForAsset(
|
179
184
|
name,
|
180
185
|
content,
|
@@ -191,7 +196,9 @@ class NormalModule extends Module {
|
|
191
196
|
};
|
192
197
|
|
193
198
|
compilation.hooks.normalModuleLoader.call(loaderContext, this);
|
194
|
-
if (options.loader)
|
199
|
+
if (options.loader) {
|
200
|
+
Object.assign(loaderContext, options.loader);
|
201
|
+
}
|
195
202
|
|
196
203
|
return loaderContext;
|
197
204
|
}
|
@@ -21,11 +21,18 @@ const cachedMerge = require("./util/cachedMerge");
|
|
21
21
|
const EMPTY_RESOLVE_OPTIONS = {};
|
22
22
|
|
23
23
|
const loaderToIdent = data => {
|
24
|
-
if (!data.options)
|
25
|
-
|
26
|
-
|
24
|
+
if (!data.options) {
|
25
|
+
return data.loader;
|
26
|
+
}
|
27
|
+
if (typeof data.options === "string") {
|
28
|
+
return data.loader + "?" + data.options;
|
29
|
+
}
|
30
|
+
if (typeof data.options !== "object") {
|
27
31
|
throw new Error("loader options must be string or object");
|
28
|
-
|
32
|
+
}
|
33
|
+
if (data.ident) {
|
34
|
+
return data.loader + "??" + data.ident;
|
35
|
+
}
|
29
36
|
return data.loader + "?" + JSON.stringify(data.options);
|
30
37
|
};
|
31
38
|
|
@@ -252,16 +259,21 @@ class NormalModuleFactory extends Tapable {
|
|
252
259
|
const useLoadersPre = [];
|
253
260
|
for (const r of result) {
|
254
261
|
if (r.type === "use") {
|
255
|
-
if (r.enforce === "post" && !noPrePostAutoLoaders)
|
262
|
+
if (r.enforce === "post" && !noPrePostAutoLoaders) {
|
256
263
|
useLoadersPost.push(r.value);
|
257
|
-
else if (
|
264
|
+
} else if (
|
258
265
|
r.enforce === "pre" &&
|
259
266
|
!noPreAutoLoaders &&
|
260
267
|
!noPrePostAutoLoaders
|
261
|
-
)
|
268
|
+
) {
|
262
269
|
useLoadersPre.push(r.value);
|
263
|
-
else if (
|
270
|
+
} else if (
|
271
|
+
!r.enforce &&
|
272
|
+
!noAutoLoaders &&
|
273
|
+
!noPrePostAutoLoaders
|
274
|
+
) {
|
264
275
|
useLoaders.push(r.value);
|
276
|
+
}
|
265
277
|
} else if (
|
266
278
|
typeof r.value === "object" &&
|
267
279
|
r.value !== null &&
|
@@ -428,8 +440,11 @@ class NormalModuleFactory extends Tapable {
|
|
428
440
|
getParser(type, parserOptions) {
|
429
441
|
let ident = type;
|
430
442
|
if (parserOptions) {
|
431
|
-
if (parserOptions.ident)
|
432
|
-
|
443
|
+
if (parserOptions.ident) {
|
444
|
+
ident = `${type}|${parserOptions.ident}`;
|
445
|
+
} else {
|
446
|
+
ident = JSON.stringify([type, parserOptions]);
|
447
|
+
}
|
433
448
|
}
|
434
449
|
if (ident in this.parserCache) {
|
435
450
|
return this.parserCache[ident];
|
@@ -449,8 +464,11 @@ class NormalModuleFactory extends Tapable {
|
|
449
464
|
getGenerator(type, generatorOptions) {
|
450
465
|
let ident = type;
|
451
466
|
if (generatorOptions) {
|
452
|
-
if (generatorOptions.ident)
|
453
|
-
|
467
|
+
if (generatorOptions.ident) {
|
468
|
+
ident = `${type}|${generatorOptions.ident}`;
|
469
|
+
} else {
|
470
|
+
ident = JSON.stringify([type, generatorOptions]);
|
471
|
+
}
|
454
472
|
}
|
455
473
|
if (ident in this.generatorCache) {
|
456
474
|
return this.generatorCache[ident];
|
package/lib/OptionsDefaulter.js
CHANGED
@@ -36,8 +36,9 @@ class OptionsDefaulter {
|
|
36
36
|
for (let name in this.defaults) {
|
37
37
|
switch (this.config[name]) {
|
38
38
|
case undefined:
|
39
|
-
if (getProperty(options, name) === undefined)
|
39
|
+
if (getProperty(options, name) === undefined) {
|
40
40
|
setProperty(options, name, this.defaults[name]);
|
41
|
+
}
|
41
42
|
break;
|
42
43
|
case "call":
|
43
44
|
setProperty(
|
@@ -47,12 +48,15 @@ class OptionsDefaulter {
|
|
47
48
|
);
|
48
49
|
break;
|
49
50
|
case "make":
|
50
|
-
if (getProperty(options, name) === undefined)
|
51
|
+
if (getProperty(options, name) === undefined) {
|
51
52
|
setProperty(options, name, this.defaults[name].call(this, options));
|
53
|
+
}
|
52
54
|
break;
|
53
55
|
case "append": {
|
54
56
|
let oldValue = getProperty(options, name);
|
55
|
-
if (!Array.isArray(oldValue))
|
57
|
+
if (!Array.isArray(oldValue)) {
|
58
|
+
oldValue = [];
|
59
|
+
}
|
56
60
|
oldValue.push(...this.defaults[name]);
|
57
61
|
setProperty(options, name, oldValue);
|
58
62
|
break;
|