webpack 4.14.0 → 4.16.1
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/LICENSE +20 -20
- package/README.md +5 -2
- package/bin/webpack.js +7 -2
- package/buildin/amd-define.js +3 -3
- package/buildin/amd-options.js +2 -2
- package/buildin/system.js +7 -7
- package/hot/dev-server.js +2 -2
- package/hot/emitter.js +2 -2
- package/hot/only-dev-server.js +2 -2
- package/hot/poll.js +5 -2
- package/hot/signal.js +2 -2
- package/lib/AsyncDependenciesBlock.js +44 -0
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/Chunk.js +56 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/ChunkTemplate.js +14 -2
- package/lib/CommentCompilationWarning.js +3 -3
- package/lib/CompatibilityPlugin.js +1 -1
- package/lib/Compilation.js +442 -37
- package/lib/Compiler.js +57 -4
- package/lib/ContextModule.js +23 -16
- package/lib/DefinePlugin.js +49 -0
- package/lib/DelegatedModule.js +9 -1
- package/lib/DelegatedModuleFactoryPlugin.js +7 -1
- package/lib/DependenciesBlock.js +36 -3
- package/lib/DependenciesBlockVariable.js +22 -0
- package/lib/Dependency.js +33 -6
- package/lib/DllEntryPlugin.js +4 -1
- package/lib/DynamicEntryPlugin.js +21 -1
- package/lib/EntryOptionPlugin.js +12 -0
- package/lib/Entrypoint.js +1 -1
- package/lib/EnvironmentPlugin.js +8 -1
- package/lib/ExtendedAPIPlugin.js +8 -4
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/Generator.js +1 -1
- package/lib/GraphHelpers.js +2 -1
- package/lib/HotModuleReplacement.runtime.js +8 -5
- package/lib/HotModuleReplacementPlugin.js +115 -117
- package/lib/IgnorePlugin.js +1 -1
- package/lib/MainTemplate.js +19 -4
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +9 -3
- package/lib/ModuleReason.js +8 -0
- package/lib/MultiEntryPlugin.js +25 -3
- package/lib/NormalModule.js +5 -23
- package/lib/NullFactory.js +12 -12
- package/lib/OptionsApply.js +10 -10
- package/lib/RuleSet.js +3 -3
- package/lib/SingleEntryPlugin.js +20 -1
- package/lib/Stats.js +12 -5
- package/lib/Template.js +4 -1
- package/lib/UmdMainTemplatePlugin.js +12 -12
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +92 -10
- package/lib/WebpackOptionsDefaulter.js +23 -6
- package/lib/WebpackOptionsValidationError.js +0 -1
- package/lib/compareLocations.js +13 -17
- package/lib/debug/ProfilingPlugin.js +5 -7
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -6
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +0 -2
- package/lib/dependencies/AMDRequireItemDependency.js +22 -22
- package/lib/dependencies/CommonJsRequireDependency.js +22 -22
- package/lib/dependencies/CriticalDependencyWarning.js +20 -20
- package/lib/dependencies/DelegatedSourceDependency.js +18 -18
- package/lib/dependencies/DllEntryDependency.js +20 -20
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/LoaderDependency.js +3 -0
- package/lib/dependencies/LoaderPlugin.js +21 -2
- package/lib/dependencies/LocalModule.js +23 -23
- package/lib/dependencies/ModuleDependency.js +3 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -23
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -23
- package/lib/dependencies/MultiEntryDependency.js +5 -0
- package/lib/dependencies/PrefetchDependency.js +18 -18
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -21
- package/lib/dependencies/RequireResolveDependency.js +22 -22
- package/lib/dependencies/SingleEntryDependency.js +3 -0
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/formatLocation.js +55 -41
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +2 -2
- package/lib/node/NodeOutputFileSystem.js +22 -22
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +1 -0
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +168 -18
- package/lib/util/Semaphore.js +12 -0
- package/lib/util/SetHelpers.js +4 -4
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cachedMerge.js +1 -1
- package/lib/util/createHash.js +15 -0
- package/lib/util/deterministicGrouping.js +251 -0
- package/lib/util/identifier.js +27 -0
- package/lib/wasm/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm/WasmMainTemplatePlugin.js +10 -4
- package/lib/wasm/WebAssemblyGenerator.js +12 -12
- package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
- package/lib/wasm/WebAssemblyModulesPlugin.js +28 -0
- package/lib/web/JsonpMainTemplatePlugin.js +1 -1
- package/lib/web/WebEnvironmentPlugin.js +18 -18
- package/lib/webpack.js +4 -0
- package/lib/webpack.web.js +2 -2
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +1 -1
- package/package.json +27 -17
- package/schemas/WebpackOptions.json +71 -9
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
package/lib/RuleSet.js
CHANGED
@@ -75,13 +75,13 @@ normalized:
|
|
75
75
|
"use strict";
|
76
76
|
|
77
77
|
const notMatcher = matcher => {
|
78
|
-
return
|
78
|
+
return str => {
|
79
79
|
return !matcher(str);
|
80
80
|
};
|
81
81
|
};
|
82
82
|
|
83
83
|
const orMatcher = items => {
|
84
|
-
return
|
84
|
+
return str => {
|
85
85
|
for (let i = 0; i < items.length; i++) {
|
86
86
|
if (items[i](str)) return true;
|
87
87
|
}
|
@@ -90,7 +90,7 @@ const orMatcher = items => {
|
|
90
90
|
};
|
91
91
|
|
92
92
|
const andMatcher = items => {
|
93
|
-
return
|
93
|
+
return str => {
|
94
94
|
for (let i = 0; i < items.length; i++) {
|
95
95
|
if (!items[i](str)) return false;
|
96
96
|
}
|
package/lib/SingleEntryPlugin.js
CHANGED
@@ -5,13 +5,27 @@
|
|
5
5
|
"use strict";
|
6
6
|
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
7
7
|
|
8
|
+
/** @typedef {import("./Compiler")} Compiler */
|
9
|
+
|
8
10
|
class SingleEntryPlugin {
|
11
|
+
/**
|
12
|
+
* An entry plugin which will handle
|
13
|
+
* creation of the SingleEntryDependency
|
14
|
+
*
|
15
|
+
* @param {string} context context path
|
16
|
+
* @param {string} entry entry path
|
17
|
+
* @param {string} name entry key name
|
18
|
+
*/
|
9
19
|
constructor(context, entry, name) {
|
10
20
|
this.context = context;
|
11
21
|
this.entry = entry;
|
12
22
|
this.name = name;
|
13
23
|
}
|
14
24
|
|
25
|
+
/**
|
26
|
+
* @param {Compiler} compiler the compiler instance
|
27
|
+
* @returns {void}
|
28
|
+
*/
|
15
29
|
apply(compiler) {
|
16
30
|
compiler.hooks.compilation.tap(
|
17
31
|
"SingleEntryPlugin",
|
@@ -34,9 +48,14 @@ class SingleEntryPlugin {
|
|
34
48
|
);
|
35
49
|
}
|
36
50
|
|
51
|
+
/**
|
52
|
+
* @param {string} entry entry request
|
53
|
+
* @param {string} name entry name
|
54
|
+
* @returns {SingleEntryDependency} the dependency
|
55
|
+
*/
|
37
56
|
static createDependency(entry, name) {
|
38
57
|
const dep = new SingleEntryDependency(entry);
|
39
|
-
dep.loc = name;
|
58
|
+
dep.loc = { name };
|
40
59
|
return dep;
|
41
60
|
}
|
42
61
|
}
|
package/lib/Stats.js
CHANGED
@@ -15,6 +15,12 @@ const optionsOrFallback = (...args) => {
|
|
15
15
|
return optionValues.find(optionValue => typeof optionValue !== "undefined");
|
16
16
|
};
|
17
17
|
|
18
|
+
const compareId = (a, b) => {
|
19
|
+
if (a < b) return -1;
|
20
|
+
if (a > b) return 1;
|
21
|
+
return 0;
|
22
|
+
};
|
23
|
+
|
18
24
|
class Stats {
|
19
25
|
constructor(compilation) {
|
20
26
|
this.compilation = compilation;
|
@@ -108,10 +114,11 @@ class Stats {
|
|
108
114
|
if (typeof item === "string") {
|
109
115
|
const regExp = new RegExp(
|
110
116
|
`[\\\\/]${item.replace(
|
117
|
+
// eslint-disable-next-line no-useless-escape
|
111
118
|
/[-[\]{}()*+?.\\^$|]/g,
|
112
119
|
"\\$&"
|
113
120
|
)}([\\\\/]|$|!|\\?)`
|
114
|
-
);
|
121
|
+
);
|
115
122
|
return ident => regExp.test(ident);
|
116
123
|
}
|
117
124
|
if (item && typeof item === "object" && typeof item.test === "function") {
|
@@ -542,7 +549,7 @@ class Stats {
|
|
542
549
|
}
|
543
550
|
return obj;
|
544
551
|
})
|
545
|
-
.sort(
|
552
|
+
.sort(compareId);
|
546
553
|
}
|
547
554
|
if (showUsedExports) {
|
548
555
|
if (module.used === true) {
|
@@ -613,9 +620,9 @@ class Stats {
|
|
613
620
|
names: chunk.name ? [chunk.name] : [],
|
614
621
|
files: chunk.files.slice(),
|
615
622
|
hash: chunk.renderedHash,
|
616
|
-
siblings: Array.from(siblings).sort(),
|
617
|
-
parents: Array.from(parents).sort(),
|
618
|
-
children: Array.from(children).sort(),
|
623
|
+
siblings: Array.from(siblings).sort(compareId),
|
624
|
+
parents: Array.from(parents).sort(compareId),
|
625
|
+
children: Array.from(children).sort(compareId),
|
619
626
|
childrenByOrder: childIdByOrder
|
620
627
|
};
|
621
628
|
if (showChunkModules) {
|
package/lib/Template.js
CHANGED
@@ -22,6 +22,8 @@ const COMMENT_END_REGEX = /\*\//g;
|
|
22
22
|
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
|
23
23
|
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
24
24
|
|
25
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
26
|
+
|
25
27
|
/**
|
26
28
|
* @typedef {Object} HasId
|
27
29
|
* @property {number | string} id
|
@@ -230,6 +232,7 @@ class Template {
|
|
230
232
|
source.add("[]");
|
231
233
|
return source;
|
232
234
|
}
|
235
|
+
/** @type {{id: string|number, source: Source|string}[]} */
|
233
236
|
var allModules = modules.map(module => {
|
234
237
|
return {
|
235
238
|
id: module.id,
|
@@ -241,7 +244,7 @@ class Template {
|
|
241
244
|
if (removedModules && removedModules.length > 0) {
|
242
245
|
for (const id of removedModules) {
|
243
246
|
allModules.push({
|
244
|
-
id
|
247
|
+
id,
|
245
248
|
source: "false"
|
246
249
|
});
|
247
250
|
}
|
@@ -107,14 +107,14 @@ class UmdMainTemplatePlugin {
|
|
107
107
|
requiredExternals = externals;
|
108
108
|
}
|
109
109
|
|
110
|
-
|
110
|
+
const replaceKeys = str => {
|
111
111
|
return mainTemplate.getAssetPath(str, {
|
112
112
|
hash,
|
113
113
|
chunk
|
114
114
|
});
|
115
|
-
}
|
115
|
+
};
|
116
116
|
|
117
|
-
|
117
|
+
const externalsDepsArray = modules => {
|
118
118
|
return `[${replaceKeys(
|
119
119
|
modules
|
120
120
|
.map(m =>
|
@@ -124,9 +124,9 @@ class UmdMainTemplatePlugin {
|
|
124
124
|
)
|
125
125
|
.join(", ")
|
126
126
|
)}]`;
|
127
|
-
}
|
127
|
+
};
|
128
128
|
|
129
|
-
|
129
|
+
const externalsRootArray = modules => {
|
130
130
|
return replaceKeys(
|
131
131
|
modules
|
132
132
|
.map(m => {
|
@@ -136,9 +136,9 @@ class UmdMainTemplatePlugin {
|
|
136
136
|
})
|
137
137
|
.join(", ")
|
138
138
|
);
|
139
|
-
}
|
139
|
+
};
|
140
140
|
|
141
|
-
|
141
|
+
const externalsRequireArray = type => {
|
142
142
|
return replaceKeys(
|
143
143
|
externals
|
144
144
|
.map(m => {
|
@@ -166,20 +166,20 @@ class UmdMainTemplatePlugin {
|
|
166
166
|
})
|
167
167
|
.join(", ")
|
168
168
|
);
|
169
|
-
}
|
169
|
+
};
|
170
170
|
|
171
|
-
|
171
|
+
const externalsArguments = modules => {
|
172
172
|
return modules
|
173
173
|
.map(
|
174
174
|
m =>
|
175
175
|
`__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__`
|
176
176
|
)
|
177
177
|
.join(", ");
|
178
|
-
}
|
178
|
+
};
|
179
179
|
|
180
|
-
|
180
|
+
const libraryName = library => {
|
181
181
|
return JSON.stringify(replaceKeys([].concat(library).pop()));
|
182
|
-
}
|
182
|
+
};
|
183
183
|
|
184
184
|
let amdFactory;
|
185
185
|
if (optionalExternals.length > 0) {
|
package/lib/UseStrictPlugin.js
CHANGED
package/lib/WebpackError.js
CHANGED
@@ -13,6 +13,10 @@ class WebpackError extends Error {
|
|
13
13
|
super(message);
|
14
14
|
|
15
15
|
this.details = undefined;
|
16
|
+
this.missing = undefined;
|
17
|
+
this.origin = undefined;
|
18
|
+
this.dependencies = undefined;
|
19
|
+
this.module = undefined;
|
16
20
|
|
17
21
|
Error.captureStackTrace(this, this.constructor);
|
18
22
|
}
|
@@ -46,7 +46,9 @@ const RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin"
|
|
46
46
|
const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
47
47
|
const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
48
48
|
const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
49
|
-
const
|
49
|
+
const OccurrenceChunkOrderPlugin = require("./optimize/OccurrenceChunkOrderPlugin");
|
50
|
+
const OccurrenceModuleOrderPlugin = require("./optimize/OccurrenceModuleOrderPlugin");
|
51
|
+
const NaturalChunkOrderPlugin = require("./optimize/NaturalChunkOrderPlugin");
|
50
52
|
const SideEffectsFlagPlugin = require("./optimize/SideEffectsFlagPlugin");
|
51
53
|
const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
|
52
54
|
const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
|
@@ -171,9 +173,13 @@ class WebpackOptionsApply extends OptionsApply {
|
|
171
173
|
break;
|
172
174
|
case "electron-renderer":
|
173
175
|
JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin");
|
176
|
+
FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
|
174
177
|
NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
175
178
|
ExternalsPlugin = require("./ExternalsPlugin");
|
176
179
|
new JsonpTemplatePlugin().apply(compiler);
|
180
|
+
new FetchCompileWasmTemplatePlugin({
|
181
|
+
mangleImports: options.optimization.mangleWasmImports
|
182
|
+
}).apply(compiler);
|
177
183
|
new FunctionModulePlugin().apply(compiler);
|
178
184
|
new NodeTargetPlugin().apply(compiler);
|
179
185
|
new ExternalsPlugin("commonjs", [
|
@@ -325,9 +331,6 @@ class WebpackOptionsApply extends OptionsApply {
|
|
325
331
|
if (options.optimization.flagIncludedChunks) {
|
326
332
|
new FlagIncludedChunksPlugin().apply(compiler);
|
327
333
|
}
|
328
|
-
if (options.optimization.occurrenceOrder) {
|
329
|
-
new OccurrenceOrderPlugin(true).apply(compiler);
|
330
|
-
}
|
331
334
|
if (options.optimization.sideEffects) {
|
332
335
|
new SideEffectsFlagPlugin().apply(compiler);
|
333
336
|
}
|
@@ -352,14 +355,93 @@ class WebpackOptionsApply extends OptionsApply {
|
|
352
355
|
if (options.optimization.checkWasmTypes) {
|
353
356
|
new WasmFinalizeExportsPlugin().apply(compiler);
|
354
357
|
}
|
355
|
-
|
356
|
-
|
358
|
+
let moduleIds = options.optimization.moduleIds;
|
359
|
+
if (moduleIds === undefined) {
|
360
|
+
// TODO webpack 5 remove all these options
|
361
|
+
if (options.optimization.occurrenceOrder) {
|
362
|
+
moduleIds = "size";
|
363
|
+
}
|
364
|
+
if (options.optimization.namedModules) {
|
365
|
+
moduleIds = "named";
|
366
|
+
}
|
367
|
+
if (options.optimization.hashedModuleIds) {
|
368
|
+
moduleIds = "hashed";
|
369
|
+
}
|
370
|
+
if (moduleIds === undefined) {
|
371
|
+
moduleIds = "natural";
|
372
|
+
}
|
357
373
|
}
|
358
|
-
if (
|
359
|
-
|
374
|
+
if (moduleIds) {
|
375
|
+
switch (moduleIds) {
|
376
|
+
case "natural":
|
377
|
+
// TODO webpack 5: see hint in Compilation.sortModules
|
378
|
+
break;
|
379
|
+
case "named":
|
380
|
+
new NamedModulesPlugin().apply(compiler);
|
381
|
+
break;
|
382
|
+
case "hashed":
|
383
|
+
new HashedModuleIdsPlugin().apply(compiler);
|
384
|
+
break;
|
385
|
+
case "size":
|
386
|
+
new OccurrenceModuleOrderPlugin({
|
387
|
+
prioritiseInitial: true
|
388
|
+
}).apply(compiler);
|
389
|
+
break;
|
390
|
+
case "total-size":
|
391
|
+
new OccurrenceModuleOrderPlugin({
|
392
|
+
prioritiseInitial: false
|
393
|
+
}).apply(compiler);
|
394
|
+
break;
|
395
|
+
default:
|
396
|
+
throw new Error(
|
397
|
+
`webpack bug: moduleIds: ${moduleIds} is not implemented`
|
398
|
+
);
|
399
|
+
}
|
400
|
+
}
|
401
|
+
let chunkIds = options.optimization.chunkIds;
|
402
|
+
if (chunkIds === undefined) {
|
403
|
+
// TODO webpack 5 remove all these options
|
404
|
+
if (options.optimization.occurrenceOrder) {
|
405
|
+
// This looks weird but it's for backward-compat
|
406
|
+
// This bug already existed before adding this feature
|
407
|
+
chunkIds = "total-size";
|
408
|
+
}
|
409
|
+
if (options.optimization.namedChunks) {
|
410
|
+
chunkIds = "named";
|
411
|
+
}
|
412
|
+
if (chunkIds === undefined) {
|
413
|
+
chunkIds = "natural";
|
414
|
+
}
|
360
415
|
}
|
361
|
-
if (
|
362
|
-
|
416
|
+
if (chunkIds) {
|
417
|
+
switch (chunkIds) {
|
418
|
+
case "natural":
|
419
|
+
new NaturalChunkOrderPlugin().apply(compiler);
|
420
|
+
break;
|
421
|
+
case "named":
|
422
|
+
// TODO webapck 5: for backward-compat this need to have OccurrenceChunkOrderPlugin too
|
423
|
+
// The NamedChunksPlugin doesn't give every chunk a name
|
424
|
+
// This should be fixed, and the OccurrenceChunkOrderPlugin should be removed here.
|
425
|
+
new OccurrenceChunkOrderPlugin({
|
426
|
+
prioritiseInitial: false
|
427
|
+
}).apply(compiler);
|
428
|
+
new NamedChunksPlugin().apply(compiler);
|
429
|
+
break;
|
430
|
+
case "size":
|
431
|
+
new OccurrenceChunkOrderPlugin({
|
432
|
+
prioritiseInitial: true
|
433
|
+
}).apply(compiler);
|
434
|
+
break;
|
435
|
+
case "total-size":
|
436
|
+
new OccurrenceChunkOrderPlugin({
|
437
|
+
prioritiseInitial: false
|
438
|
+
}).apply(compiler);
|
439
|
+
break;
|
440
|
+
default:
|
441
|
+
throw new Error(
|
442
|
+
`webpack bug: chunkIds: ${chunkIds} is not implemented`
|
443
|
+
);
|
444
|
+
}
|
363
445
|
}
|
364
446
|
if (options.optimization.nodeEnv) {
|
365
447
|
new DefinePlugin({
|
@@ -17,6 +17,16 @@ const isWebLikeTarget = options => {
|
|
17
17
|
return options.target === "web" || options.target === "webworker";
|
18
18
|
};
|
19
19
|
|
20
|
+
const getDevtoolNamespace = library => {
|
21
|
+
// if options.output.library is a string
|
22
|
+
if (Array.isArray(library)) {
|
23
|
+
return library.join(".");
|
24
|
+
} else if (typeof library === "object") {
|
25
|
+
return getDevtoolNamespace(library.root);
|
26
|
+
}
|
27
|
+
return library || "";
|
28
|
+
};
|
29
|
+
|
20
30
|
class WebpackOptionsDefaulter extends OptionsDefaulter {
|
21
31
|
constructor() {
|
22
32
|
super();
|
@@ -136,12 +146,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
136
146
|
}
|
137
147
|
});
|
138
148
|
this.set("output.devtoolNamespace", "make", options => {
|
139
|
-
|
140
|
-
return options.output.library.join(".");
|
141
|
-
} else if (typeof options.output.library === "object") {
|
142
|
-
return options.output.library.root || "";
|
143
|
-
}
|
144
|
-
return options.output.library || "";
|
149
|
+
return getDevtoolNamespace(options.output.library);
|
145
150
|
});
|
146
151
|
this.set("output.libraryTarget", "var");
|
147
152
|
this.set("output.path", path.join(process.cwd(), "dist"));
|
@@ -201,6 +206,9 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
201
206
|
this.set("optimization.flagIncludedChunks", "make", options =>
|
202
207
|
isProductionLikeMode(options)
|
203
208
|
);
|
209
|
+
// TODO webpack 5 add `moduleIds: "named"` default for development
|
210
|
+
// TODO webpack 5 add `moduleIds: "size"` default for production
|
211
|
+
// TODO webpack 5 remove optimization.occurrenceOrder
|
204
212
|
this.set("optimization.occurrenceOrder", "make", options =>
|
205
213
|
isProductionLikeMode(options)
|
206
214
|
);
|
@@ -215,6 +223,9 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
215
223
|
isProductionLikeMode(options)
|
216
224
|
);
|
217
225
|
this.set("optimization.splitChunks", {});
|
226
|
+
this.set("optimization.splitChunks.hidePathInfo", "make", options => {
|
227
|
+
return isProductionLikeMode(options);
|
228
|
+
});
|
218
229
|
this.set("optimization.splitChunks.chunks", "async");
|
219
230
|
this.set("optimization.splitChunks.minSize", "make", options => {
|
220
231
|
return isProductionLikeMode(options) ? 30000 : 10000;
|
@@ -230,11 +241,13 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
230
241
|
this.set("optimization.splitChunks.name", true);
|
231
242
|
this.set("optimization.splitChunks.cacheGroups", {});
|
232
243
|
this.set("optimization.splitChunks.cacheGroups.default", {
|
244
|
+
automaticNamePrefix: "",
|
233
245
|
reuseExistingChunk: true,
|
234
246
|
minChunks: 2,
|
235
247
|
priority: -20
|
236
248
|
});
|
237
249
|
this.set("optimization.splitChunks.cacheGroups.vendors", {
|
250
|
+
automaticNamePrefix: "vendors",
|
238
251
|
test: /[\\/]node_modules[\\/]/,
|
239
252
|
priority: -10
|
240
253
|
});
|
@@ -258,12 +271,16 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
258
271
|
isProductionLikeMode(options)
|
259
272
|
);
|
260
273
|
this.set("optimization.mangleWasmImports", false);
|
274
|
+
// TODO webpack 5 remove optimization.namedModules
|
261
275
|
this.set(
|
262
276
|
"optimization.namedModules",
|
263
277
|
"make",
|
264
278
|
options => options.mode === "development"
|
265
279
|
);
|
266
280
|
this.set("optimization.hashedModuleIds", false);
|
281
|
+
// TODO webpack 5 add `chunkIds: "named"` default for development
|
282
|
+
// TODO webpack 5 add `chunkIds: "size"` default for production
|
283
|
+
// TODO webpack 5 remove optimization.namedChunks
|
267
284
|
this.set(
|
268
285
|
"optimization.namedChunks",
|
269
286
|
"make",
|
package/lib/compareLocations.js
CHANGED
@@ -4,23 +4,13 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
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
|
-
*/
|
7
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
19
8
|
|
9
|
+
// TODO webpack 5 remove string type from a and b
|
20
10
|
/**
|
21
11
|
* Compare two locations
|
22
|
-
* @param {string|
|
23
|
-
* @param {string|
|
12
|
+
* @param {string|DependencyLocation} a A location node
|
13
|
+
* @param {string|DependencyLocation} b A location node
|
24
14
|
* @returns {-1|0|1} sorting comparator value
|
25
15
|
*/
|
26
16
|
module.exports = (a, b) => {
|
@@ -38,7 +28,7 @@ module.exports = (a, b) => {
|
|
38
28
|
if (typeof b === "string") {
|
39
29
|
return -1;
|
40
30
|
} else if (typeof b === "object") {
|
41
|
-
if (
|
31
|
+
if ("start" in a && "start" in b) {
|
42
32
|
const ap = a.start;
|
43
33
|
const bp = b.start;
|
44
34
|
if (ap.line < bp.line) return -1;
|
@@ -46,8 +36,14 @@ module.exports = (a, b) => {
|
|
46
36
|
if (ap.column < bp.column) return -1;
|
47
37
|
if (ap.column > bp.column) return 1;
|
48
38
|
}
|
49
|
-
if (a
|
50
|
-
|
39
|
+
if ("name" in a && "name" in b) {
|
40
|
+
if (a.name < b.name) return -1;
|
41
|
+
if (a.name > b.name) return 1;
|
42
|
+
}
|
43
|
+
if ("index" in a && "index" in b) {
|
44
|
+
if (a.index < b.index) return -1;
|
45
|
+
if (a.index > b.index) return 1;
|
46
|
+
}
|
51
47
|
return 0;
|
52
48
|
} else {
|
53
49
|
return 0;
|
@@ -5,7 +5,8 @@ const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
|
5
5
|
let inspector = undefined;
|
6
6
|
|
7
7
|
try {
|
8
|
-
|
8
|
+
// eslint-disable-next-line node/no-missing-require
|
9
|
+
inspector = require("inspector");
|
9
10
|
} catch (e) {
|
10
11
|
console.log("Unable to CPU profile in < node 8.0");
|
11
12
|
}
|
@@ -84,7 +85,7 @@ class Profiler {
|
|
84
85
|
* @param {string} outputPath The location where to write the log.
|
85
86
|
* @returns {Trace} The trace object
|
86
87
|
*/
|
87
|
-
|
88
|
+
const createTrace = outputPath => {
|
88
89
|
const trace = new Tracer({
|
89
90
|
noStream: true
|
90
91
|
});
|
@@ -136,10 +137,10 @@ function createTrace(outputPath) {
|
|
136
137
|
callback();
|
137
138
|
});
|
138
139
|
// Tear down the readable trace stream.
|
139
|
-
trace.
|
140
|
+
trace.push(null);
|
140
141
|
}
|
141
142
|
};
|
142
|
-
}
|
143
|
+
};
|
143
144
|
|
144
145
|
const pluginName = "ProfilingPlugin";
|
145
146
|
|
@@ -354,7 +355,6 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
354
355
|
switch (type) {
|
355
356
|
case "promise":
|
356
357
|
return (...args) => {
|
357
|
-
// eslint-disable-line
|
358
358
|
const id = ++tracer.counter;
|
359
359
|
tracer.trace.begin({
|
360
360
|
name,
|
@@ -373,7 +373,6 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
373
373
|
};
|
374
374
|
case "async":
|
375
375
|
return (...args) => {
|
376
|
-
// eslint-disable-line
|
377
376
|
const id = ++tracer.counter;
|
378
377
|
tracer.trace.begin({
|
379
378
|
name,
|
@@ -392,7 +391,6 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
392
391
|
};
|
393
392
|
case "sync":
|
394
393
|
return (...args) => {
|
395
|
-
// eslint-disable-line
|
396
394
|
const id = ++tracer.counter;
|
397
395
|
// Do not instrument ourself due to the CPU
|
398
396
|
// profile needing to be the last event in the trace.
|
@@ -23,17 +23,17 @@ const isBoundFunctionExpression = expr => {
|
|
23
23
|
return true;
|
24
24
|
};
|
25
25
|
|
26
|
-
|
26
|
+
const isUnboundFunctionExpression = expr => {
|
27
27
|
if (expr.type === "FunctionExpression") return true;
|
28
28
|
if (expr.type === "ArrowFunctionExpression") return true;
|
29
29
|
return false;
|
30
|
-
}
|
30
|
+
};
|
31
31
|
|
32
|
-
|
32
|
+
const isCallable = expr => {
|
33
33
|
if (isUnboundFunctionExpression(expr)) return true;
|
34
34
|
if (isBoundFunctionExpression(expr)) return true;
|
35
35
|
return false;
|
36
|
-
}
|
36
|
+
};
|
37
37
|
|
38
38
|
class AMDDefineDependencyParserPlugin {
|
39
39
|
constructor(options) {
|
@@ -80,7 +80,6 @@ class AMDDefineDependencyParserPlugin {
|
|
80
80
|
request
|
81
81
|
))
|
82
82
|
) {
|
83
|
-
// eslint-disable-line no-cond-assign
|
84
83
|
dep = new LocalModuleDependency(localModule, undefined, false);
|
85
84
|
dep.loc = expr.loc;
|
86
85
|
parser.state.current.addDependency(dep);
|
@@ -121,7 +120,6 @@ class AMDDefineDependencyParserPlugin {
|
|
121
120
|
namedModule
|
122
121
|
))
|
123
122
|
) {
|
124
|
-
// eslint-disable-line no-cond-assign
|
125
123
|
dep = new LocalModuleDependency(localModule, param.range, false);
|
126
124
|
} else {
|
127
125
|
dep = this.newRequireItemDependency(param.string, param.range);
|
@@ -79,7 +79,6 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
79
79
|
request
|
80
80
|
))
|
81
81
|
) {
|
82
|
-
// eslint-disable-line no-cond-assign
|
83
82
|
dep = new LocalModuleDependency(localModule, undefined, false);
|
84
83
|
dep.loc = expr.loc;
|
85
84
|
parser.state.current.addDependency(dep);
|
@@ -127,7 +126,6 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
127
126
|
param.string
|
128
127
|
))
|
129
128
|
) {
|
130
|
-
// eslint-disable-line no-cond-assign
|
131
129
|
dep = new LocalModuleDependency(localModule, param.range, false);
|
132
130
|
} else {
|
133
131
|
dep = this.newRequireItemDependency(param.string, param.range);
|
@@ -1,22 +1,22 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
const ModuleDependency = require("./ModuleDependency");
|
7
|
-
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
8
|
-
|
9
|
-
class AMDRequireItemDependency extends ModuleDependency {
|
10
|
-
constructor(request, range) {
|
11
|
-
super(request);
|
12
|
-
this.range = range;
|
13
|
-
}
|
14
|
-
|
15
|
-
get type() {
|
16
|
-
return "amd require";
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
AMDRequireItemDependency.Template = ModuleDependencyTemplateAsRequireId;
|
21
|
-
|
22
|
-
module.exports = AMDRequireItemDependency;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ModuleDependency = require("./ModuleDependency");
|
7
|
+
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
8
|
+
|
9
|
+
class AMDRequireItemDependency extends ModuleDependency {
|
10
|
+
constructor(request, range) {
|
11
|
+
super(request);
|
12
|
+
this.range = range;
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "amd require";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
AMDRequireItemDependency.Template = ModuleDependencyTemplateAsRequireId;
|
21
|
+
|
22
|
+
module.exports = AMDRequireItemDependency;
|