webpack 4.10.1 → 4.12.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.
- package/lib/AmdMainTemplatePlugin.js +3 -1
- package/lib/AsyncDependencyToInitialChunkError.js +4 -4
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/CaseSensitiveModulesWarning.js +41 -45
- package/lib/Chunk.js +56 -19
- package/lib/ChunkGroup.js +14 -6
- package/lib/CommentCompilationWarning.js +22 -0
- package/lib/Compilation.js +72 -29
- 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/EntryModuleNotFoundError.js +21 -22
- 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/HarmonyLinkingError.js +1 -2
- package/lib/HotModuleReplacement.runtime.js +13 -4
- 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 +13 -5
- package/lib/ModuleBuildError.js +22 -12
- package/lib/ModuleDependencyError.js +4 -4
- package/lib/ModuleDependencyWarning.js +4 -4
- package/lib/ModuleError.js +13 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/ModuleNotFoundError.js +23 -26
- package/lib/ModuleParseError.js +27 -14
- package/lib/ModuleWarning.js +13 -7
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +80 -16
- package/lib/NormalModuleFactory.js +67 -24
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +182 -75
- package/lib/ParserHelpers.js +6 -3
- package/lib/ProgressPlugin.js +17 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +77 -9
- package/lib/RemovedPluginError.js +1 -3
- package/lib/RequestShortener.js +15 -6
- package/lib/RuleSet.js +51 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +74 -31
- package/lib/Template.js +7 -4
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/UnsupportedFeatureWarning.js +22 -21
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +51 -23
- package/lib/WebpackOptionsDefaulter.js +15 -9
- package/lib/WebpackOptionsValidationError.js +63 -34
- package/lib/debug/ProfilingPlugin.js +11 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
- 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 +42 -11
- 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/dependencies/SystemPlugin.js +6 -6
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- 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/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
- 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 +14 -3
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
- package/lib/performance/NoAsyncChunksWarning.js +5 -5
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
- package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
- package/lib/wasm/WebAssemblyGenerator.js +117 -74
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
- package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
- package/lib/wasm/WebAssemblyParser.js +96 -24
- package/lib/wasm/WebAssemblyUtils.js +17 -6
- package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
- package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +68 -63
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +12 -11
- package/schemas/WebpackOptions.json +8 -0
package/lib/Stats.js
CHANGED
@@ -56,8 +56,8 @@ class Stats {
|
|
56
56
|
formatFilePath(filePath) {
|
57
57
|
const OPTIONS_REGEXP = /^(\s|\S)*!/;
|
58
58
|
return filePath.includes("!")
|
59
|
-
? `${filePath.replace(OPTIONS_REGEXP, "")} (${filePath})
|
60
|
-
: `${filePath}
|
59
|
+
? `${filePath.replace(OPTIONS_REGEXP, "")} (${filePath})`
|
60
|
+
: `${filePath}`;
|
61
61
|
}
|
62
62
|
|
63
63
|
hasWarnings() {
|
@@ -114,10 +114,15 @@ class Stats {
|
|
114
114
|
); // eslint-disable-line no-useless-escape
|
115
115
|
return ident => regExp.test(ident);
|
116
116
|
}
|
117
|
-
if (item && typeof item === "object" && typeof item.test === "function")
|
117
|
+
if (item && typeof item === "object" && typeof item.test === "function") {
|
118
118
|
return ident => item.test(ident);
|
119
|
-
|
120
|
-
if (typeof item === "
|
119
|
+
}
|
120
|
+
if (typeof item === "function") {
|
121
|
+
return item;
|
122
|
+
}
|
123
|
+
if (typeof item === "boolean") {
|
124
|
+
return () => item;
|
125
|
+
}
|
121
126
|
};
|
122
127
|
|
123
128
|
const compilation = this.compilation;
|
@@ -260,10 +265,9 @@ class Stats {
|
|
260
265
|
|
261
266
|
const formatError = e => {
|
262
267
|
let text = "";
|
263
|
-
if (typeof e === "string")
|
264
|
-
e = {
|
265
|
-
|
266
|
-
};
|
268
|
+
if (typeof e === "string") {
|
269
|
+
e = { message: e };
|
270
|
+
}
|
267
271
|
if (e.chunk) {
|
268
272
|
text += `chunk ${e.chunk.name || e.chunk.id}${
|
269
273
|
e.chunk.hasRuntime()
|
@@ -284,13 +288,23 @@ class Stats {
|
|
284
288
|
text += this.formatFilePath(
|
285
289
|
e.module.readableIdentifier(requestShortener)
|
286
290
|
);
|
291
|
+
if (typeof e.loc === "object") {
|
292
|
+
const locInfo = formatLocation(e.loc);
|
293
|
+
if (locInfo) text += ` ${locInfo}`;
|
294
|
+
}
|
295
|
+
text += "\n";
|
287
296
|
}
|
288
297
|
text += e.message;
|
289
|
-
if (showErrorDetails && e.details)
|
290
|
-
|
298
|
+
if (showErrorDetails && e.details) {
|
299
|
+
text += `\n${e.details}`;
|
300
|
+
}
|
301
|
+
if (showErrorDetails && e.missing) {
|
291
302
|
text += e.missing.map(item => `\n[${item}]`).join("");
|
303
|
+
}
|
292
304
|
if (showModuleTrace && e.origin) {
|
293
|
-
text += `\n @ ${
|
305
|
+
text += `\n @ ${this.formatFilePath(
|
306
|
+
e.origin.readableIdentifier(requestShortener)
|
307
|
+
)}`;
|
294
308
|
if (typeof e.originLoc === "object") {
|
295
309
|
const locInfo = formatLocation(e.originLoc);
|
296
310
|
if (locInfo) text += ` ${locInfo}`;
|
@@ -392,11 +406,13 @@ class Stats {
|
|
392
406
|
}
|
393
407
|
if (chunk.name) {
|
394
408
|
assetsByFile[asset].chunkNames.push(chunk.name);
|
395
|
-
if (obj.assetsByChunkName[chunk.name])
|
409
|
+
if (obj.assetsByChunkName[chunk.name]) {
|
396
410
|
obj.assetsByChunkName[chunk.name] = []
|
397
411
|
.concat(obj.assetsByChunkName[chunk.name])
|
398
412
|
.concat([asset]);
|
399
|
-
else
|
413
|
+
} else {
|
414
|
+
obj.assetsByChunkName[chunk.name] = asset;
|
415
|
+
}
|
400
416
|
}
|
401
417
|
}
|
402
418
|
}
|
@@ -520,15 +536,20 @@ class Stats {
|
|
520
536
|
};
|
521
537
|
if (reason.dependency) {
|
522
538
|
const locInfo = formatLocation(reason.dependency.loc);
|
523
|
-
if (locInfo)
|
539
|
+
if (locInfo) {
|
540
|
+
obj.loc = locInfo;
|
541
|
+
}
|
524
542
|
}
|
525
543
|
return obj;
|
526
544
|
})
|
527
545
|
.sort((a, b) => a.moduleId - b.moduleId);
|
528
546
|
}
|
529
547
|
if (showUsedExports) {
|
530
|
-
if (module.used === true)
|
531
|
-
|
548
|
+
if (module.used === true) {
|
549
|
+
obj.usedExports = module.usedExports;
|
550
|
+
} else if (module.used === false) {
|
551
|
+
obj.usedExports = false;
|
552
|
+
}
|
532
553
|
}
|
533
554
|
if (showProvidedExports) {
|
534
555
|
obj.providedExports = Array.isArray(module.buildMeta.providedExports)
|
@@ -662,12 +683,13 @@ class Stats {
|
|
662
683
|
const obj = new Stats(child).toJson(childOptions, forToString);
|
663
684
|
delete obj.hash;
|
664
685
|
delete obj.version;
|
665
|
-
if (child.name)
|
686
|
+
if (child.name) {
|
666
687
|
obj.name = identifierUtils.makePathsRelative(
|
667
688
|
context,
|
668
689
|
child.name,
|
669
690
|
compilation.cache
|
670
691
|
);
|
692
|
+
}
|
671
693
|
return obj;
|
672
694
|
});
|
673
695
|
}
|
@@ -745,7 +767,9 @@ class Stats {
|
|
745
767
|
const rows = array.length;
|
746
768
|
const cols = array[0].length;
|
747
769
|
const colSizes = new Array(cols);
|
748
|
-
for (let col = 0; col < cols; col++)
|
770
|
+
for (let col = 0; col < cols; col++) {
|
771
|
+
colSizes[col] = 0;
|
772
|
+
}
|
749
773
|
for (let row = 0; row < rows; row++) {
|
750
774
|
for (let col = 0; col < cols; col++) {
|
751
775
|
const value = `${getText(array, row, col)}`;
|
@@ -759,11 +783,18 @@ class Stats {
|
|
759
783
|
const format = array[row][col].color;
|
760
784
|
const value = `${getText(array, row, col)}`;
|
761
785
|
let l = value.length;
|
762
|
-
if (align[col] === "l")
|
763
|
-
|
764
|
-
|
765
|
-
|
786
|
+
if (align[col] === "l") {
|
787
|
+
format(value);
|
788
|
+
}
|
789
|
+
for (; l < colSizes[col] && col !== cols - 1; l++) {
|
790
|
+
colors.normal(" ");
|
791
|
+
}
|
792
|
+
if (align[col] === "r") {
|
793
|
+
format(value);
|
794
|
+
}
|
795
|
+
if (col + 1 < cols && colSizes[col] !== 0) {
|
766
796
|
colors.normal(splitter || " ");
|
797
|
+
}
|
767
798
|
}
|
768
799
|
newline();
|
769
800
|
}
|
@@ -981,21 +1012,26 @@ class Stats {
|
|
981
1012
|
colors.magenta(" [prefetched]");
|
982
1013
|
}
|
983
1014
|
if (module.failed) colors.red(" [failed]");
|
984
|
-
if (module.warnings)
|
1015
|
+
if (module.warnings) {
|
985
1016
|
colors.yellow(
|
986
1017
|
` [${module.warnings} warning${module.warnings === 1 ? "" : "s"}]`
|
987
1018
|
);
|
988
|
-
|
1019
|
+
}
|
1020
|
+
if (module.errors) {
|
989
1021
|
colors.red(
|
990
1022
|
` [${module.errors} error${module.errors === 1 ? "" : "s"}]`
|
991
1023
|
);
|
1024
|
+
}
|
992
1025
|
};
|
993
1026
|
|
994
1027
|
const processModuleContent = (module, prefix) => {
|
995
1028
|
if (Array.isArray(module.providedExports)) {
|
996
1029
|
colors.normal(prefix);
|
997
|
-
if (module.providedExports.length === 0)
|
998
|
-
|
1030
|
+
if (module.providedExports.length === 0) {
|
1031
|
+
colors.cyan("[no exports]");
|
1032
|
+
} else {
|
1033
|
+
colors.cyan(`[exports: ${module.providedExports.join(", ")}]`);
|
1034
|
+
}
|
999
1035
|
newline();
|
1000
1036
|
}
|
1001
1037
|
if (module.usedExports !== undefined) {
|
@@ -1285,7 +1321,9 @@ class Stats {
|
|
1285
1321
|
);
|
1286
1322
|
}
|
1287
1323
|
|
1288
|
-
while (buf[buf.length - 1] === "\n")
|
1324
|
+
while (buf[buf.length - 1] === "\n") {
|
1325
|
+
buf.pop();
|
1326
|
+
}
|
1289
1327
|
return buf.join("");
|
1290
1328
|
}
|
1291
1329
|
|
@@ -1356,13 +1394,18 @@ class Stats {
|
|
1356
1394
|
static getChildOptions(options, idx) {
|
1357
1395
|
let innerOptions;
|
1358
1396
|
if (Array.isArray(options.children)) {
|
1359
|
-
if (idx < options.children.length)
|
1397
|
+
if (idx < options.children.length) {
|
1398
|
+
innerOptions = options.children[idx];
|
1399
|
+
}
|
1360
1400
|
} else if (typeof options.children === "object" && options.children) {
|
1361
1401
|
innerOptions = options.children;
|
1362
1402
|
}
|
1363
|
-
if (typeof innerOptions === "boolean" || typeof innerOptions === "string")
|
1403
|
+
if (typeof innerOptions === "boolean" || typeof innerOptions === "string") {
|
1364
1404
|
innerOptions = Stats.presetToOptions(innerOptions);
|
1365
|
-
|
1405
|
+
}
|
1406
|
+
if (!innerOptions) {
|
1407
|
+
return options;
|
1408
|
+
}
|
1366
1409
|
const childOptions = Object.assign({}, options);
|
1367
1410
|
delete childOptions.children; // do not inherit children
|
1368
1411
|
return Object.assign(childOptions, innerOptions);
|
package/lib/Template.js
CHANGED
@@ -114,13 +114,16 @@ class Template {
|
|
114
114
|
*/
|
115
115
|
static numberToIdentifer(n) {
|
116
116
|
// lower case
|
117
|
-
if (n < DELTA_A_TO_Z)
|
117
|
+
if (n < DELTA_A_TO_Z) {
|
118
118
|
return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
|
119
|
+
}
|
119
120
|
|
120
121
|
// upper case
|
121
|
-
n
|
122
|
-
|
123
|
-
|
122
|
+
if (n < DELTA_A_TO_Z * 2) {
|
123
|
+
return String.fromCharCode(
|
124
|
+
START_UPPERCASE_ALPHABET_CODE + n - DELTA_A_TO_Z
|
125
|
+
);
|
126
|
+
}
|
124
127
|
|
125
128
|
// use multiple letters
|
126
129
|
return (
|
@@ -39,10 +39,11 @@ const getReplacer = (value, allowEmpty) => {
|
|
39
39
|
// last argument in replacer is the entire input string
|
40
40
|
const input = args[args.length - 1];
|
41
41
|
if (value === null || value === undefined) {
|
42
|
-
if (!allowEmpty)
|
42
|
+
if (!allowEmpty) {
|
43
43
|
throw new Error(
|
44
44
|
`Path variable ${match} not implemented in this context: ${input}`
|
45
45
|
);
|
46
|
+
}
|
46
47
|
return "";
|
47
48
|
} else {
|
48
49
|
return `${value}`;
|
@@ -150,8 +151,9 @@ class TemplatedPathPlugin {
|
|
150
151
|
const outputOptions = mainTemplate.outputOptions;
|
151
152
|
const chunkFilename =
|
152
153
|
outputOptions.chunkFilename || outputOptions.filename;
|
153
|
-
if (REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
|
154
|
+
if (REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename)) {
|
154
155
|
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
|
156
|
+
}
|
155
157
|
if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) {
|
156
158
|
hash.update(
|
157
159
|
JSON.stringify(
|
@@ -159,8 +161,9 @@ class TemplatedPathPlugin {
|
|
159
161
|
)
|
160
162
|
);
|
161
163
|
}
|
162
|
-
if (REGEXP_NAME_FOR_TEST.test(chunkFilename))
|
164
|
+
if (REGEXP_NAME_FOR_TEST.test(chunkFilename)) {
|
163
165
|
hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
|
166
|
+
}
|
164
167
|
}
|
165
168
|
);
|
166
169
|
});
|
@@ -144,16 +144,21 @@ class UmdMainTemplatePlugin {
|
|
144
144
|
.map(m => {
|
145
145
|
let expr;
|
146
146
|
let request = m.request;
|
147
|
-
if (typeof request === "object")
|
148
|
-
|
147
|
+
if (typeof request === "object") {
|
148
|
+
request = request[type];
|
149
|
+
}
|
150
|
+
if (typeof request === "undefined") {
|
149
151
|
throw new Error(
|
150
152
|
"Missing external configuration for type:" + type
|
151
153
|
);
|
154
|
+
}
|
152
155
|
if (Array.isArray(request)) {
|
153
156
|
expr = `require(${JSON.stringify(
|
154
157
|
request[0]
|
155
158
|
)})${accessorToObjectAccess(request.slice(1))}`;
|
156
|
-
} else
|
159
|
+
} else {
|
160
|
+
expr = `require(${JSON.stringify(request)})`;
|
161
|
+
}
|
157
162
|
if (m.optional) {
|
158
163
|
expr = `(function webpackLoadOptionalExternalModule() { try { return ${expr}; } catch(e) {} }())`;
|
159
164
|
}
|
@@ -1,21 +1,22 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const WebpackError = require("./WebpackError");
|
8
|
-
|
9
|
-
class UnsupportedFeatureWarning extends WebpackError {
|
10
|
-
constructor(module, message) {
|
11
|
-
super();
|
12
|
-
|
13
|
-
this.name = "UnsupportedFeatureWarning";
|
14
|
-
this.
|
15
|
-
this.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const WebpackError = require("./WebpackError");
|
8
|
+
|
9
|
+
class UnsupportedFeatureWarning extends WebpackError {
|
10
|
+
constructor(module, message, loc) {
|
11
|
+
super(message);
|
12
|
+
|
13
|
+
this.name = "UnsupportedFeatureWarning";
|
14
|
+
this.module = module;
|
15
|
+
this.loc = loc;
|
16
|
+
this.hideStack = true;
|
17
|
+
|
18
|
+
Error.captureStackTrace(this, this.constructor);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
module.exports = UnsupportedFeatureWarning;
|
@@ -24,8 +24,9 @@ class WarnCaseSensitiveModulesPlugin {
|
|
24
24
|
}
|
25
25
|
for (const pair of moduleWithoutCase) {
|
26
26
|
const array = pair[1];
|
27
|
-
if (array.length > 1)
|
27
|
+
if (array.length > 1) {
|
28
28
|
compilation.warnings.push(new CaseSensitiveModulesWarning(array));
|
29
|
+
}
|
29
30
|
}
|
30
31
|
});
|
31
32
|
}
|
package/lib/Watching.js
CHANGED
@@ -128,8 +128,9 @@ class Watching {
|
|
128
128
|
) => {
|
129
129
|
this.pausedWatcher = this.watcher;
|
130
130
|
this.watcher = null;
|
131
|
-
if (err)
|
132
|
-
|
131
|
+
if (err) {
|
132
|
+
return this.handler(err);
|
133
|
+
}
|
133
134
|
this.compiler.fileTimestamps = fileTimestamps;
|
134
135
|
this.compiler.contextTimestamps = contextTimestamps;
|
135
136
|
this._invalidate();
|
@@ -58,6 +58,7 @@ const NamedModulesPlugin = require("./NamedModulesPlugin");
|
|
58
58
|
const NamedChunksPlugin = require("./NamedChunksPlugin");
|
59
59
|
const DefinePlugin = require("./DefinePlugin");
|
60
60
|
const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");
|
61
|
+
const WasmFinalizeExportsPlugin = require("./wasm/WasmFinalizeExportsPlugin");
|
61
62
|
|
62
63
|
class WebpackOptionsApply extends OptionsApply {
|
63
64
|
constructor() {
|
@@ -86,7 +87,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
86
87
|
FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
|
87
88
|
NodeSourcePlugin = require("./node/NodeSourcePlugin");
|
88
89
|
new JsonpTemplatePlugin().apply(compiler);
|
89
|
-
new FetchCompileWasmTemplatePlugin(
|
90
|
+
new FetchCompileWasmTemplatePlugin({
|
91
|
+
mangleImports: options.optimization.mangleWasmImports
|
92
|
+
}).apply(compiler);
|
90
93
|
new FunctionModulePlugin().apply(compiler);
|
91
94
|
new NodeSourcePlugin(options.node).apply(compiler);
|
92
95
|
new LoaderTargetPlugin(options.target).apply(compiler);
|
@@ -96,7 +99,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
96
99
|
FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin");
|
97
100
|
NodeSourcePlugin = require("./node/NodeSourcePlugin");
|
98
101
|
new WebWorkerTemplatePlugin().apply(compiler);
|
99
|
-
new FetchCompileWasmTemplatePlugin(
|
102
|
+
new FetchCompileWasmTemplatePlugin({
|
103
|
+
mangleImports: options.optimization.mangleWasmImports
|
104
|
+
}).apply(compiler);
|
100
105
|
new FunctionModulePlugin().apply(compiler);
|
101
106
|
new NodeSourcePlugin(options.node).apply(compiler);
|
102
107
|
new LoaderTargetPlugin(options.target).apply(compiler);
|
@@ -110,7 +115,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
110
115
|
new NodeTemplatePlugin({
|
111
116
|
asyncChunkLoading: options.target === "async-node"
|
112
117
|
}).apply(compiler);
|
113
|
-
new ReadFileCompileWasmTemplatePlugin(
|
118
|
+
new ReadFileCompileWasmTemplatePlugin({
|
119
|
+
mangleImports: options.optimization.mangleWasmImports
|
120
|
+
}).apply(compiler);
|
114
121
|
new FunctionModulePlugin().apply(compiler);
|
115
122
|
new NodeTargetPlugin().apply(compiler);
|
116
123
|
new LoaderTargetPlugin("node").apply(compiler);
|
@@ -194,7 +201,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
194
201
|
}
|
195
202
|
|
196
203
|
if (options.output.library || options.output.libraryTarget !== "var") {
|
197
|
-
|
204
|
+
const LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
|
198
205
|
new LibraryTemplatePlugin(
|
199
206
|
options.output.library,
|
200
207
|
options.output.libraryTarget,
|
@@ -238,7 +245,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
238
245
|
: modern
|
239
246
|
? "\n//# source" + "MappingURL=[url]"
|
240
247
|
: null;
|
241
|
-
|
248
|
+
const Plugin = evalWrapped
|
242
249
|
? EvalSourceMapDevToolPlugin
|
243
250
|
: SourceMapDevToolPlugin;
|
244
251
|
new Plugin({
|
@@ -273,7 +280,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
273
280
|
|
274
281
|
new JavascriptModulesPlugin().apply(compiler);
|
275
282
|
new JsonModulesPlugin().apply(compiler);
|
276
|
-
new WebAssemblyModulesPlugin(
|
283
|
+
new WebAssemblyModulesPlugin({
|
284
|
+
mangleImports: options.optimization.mangleWasmImports
|
285
|
+
}).apply(compiler);
|
277
286
|
|
278
287
|
new EntryOptionPlugin().apply(compiler);
|
279
288
|
compiler.hooks.entryOption.call(options.context, options.entry);
|
@@ -298,38 +307,56 @@ class WebpackOptionsApply extends OptionsApply {
|
|
298
307
|
new ImportPlugin(options.module).apply(compiler);
|
299
308
|
new SystemPlugin(options.module).apply(compiler);
|
300
309
|
|
301
|
-
if (typeof options.mode !== "string")
|
310
|
+
if (typeof options.mode !== "string") {
|
302
311
|
new WarnNoModeSetPlugin().apply(compiler);
|
312
|
+
}
|
303
313
|
|
304
314
|
new EnsureChunkConditionsPlugin().apply(compiler);
|
305
|
-
if (options.optimization.removeAvailableModules)
|
315
|
+
if (options.optimization.removeAvailableModules) {
|
306
316
|
new RemoveParentModulesPlugin().apply(compiler);
|
307
|
-
|
317
|
+
}
|
318
|
+
if (options.optimization.removeEmptyChunks) {
|
308
319
|
new RemoveEmptyChunksPlugin().apply(compiler);
|
309
|
-
|
320
|
+
}
|
321
|
+
if (options.optimization.mergeDuplicateChunks) {
|
310
322
|
new MergeDuplicateChunksPlugin().apply(compiler);
|
311
|
-
|
323
|
+
}
|
324
|
+
if (options.optimization.flagIncludedChunks) {
|
312
325
|
new FlagIncludedChunksPlugin().apply(compiler);
|
313
|
-
|
326
|
+
}
|
327
|
+
if (options.optimization.occurrenceOrder) {
|
314
328
|
new OccurrenceOrderPlugin(true).apply(compiler);
|
315
|
-
|
329
|
+
}
|
330
|
+
if (options.optimization.sideEffects) {
|
316
331
|
new SideEffectsFlagPlugin().apply(compiler);
|
317
|
-
|
332
|
+
}
|
333
|
+
if (options.optimization.providedExports) {
|
318
334
|
new FlagDependencyExportsPlugin().apply(compiler);
|
319
|
-
|
335
|
+
}
|
336
|
+
if (options.optimization.usedExports) {
|
320
337
|
new FlagDependencyUsagePlugin().apply(compiler);
|
321
|
-
|
338
|
+
}
|
339
|
+
if (options.optimization.concatenateModules) {
|
322
340
|
new ModuleConcatenationPlugin().apply(compiler);
|
323
|
-
|
341
|
+
}
|
342
|
+
if (options.optimization.splitChunks) {
|
324
343
|
new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
|
325
|
-
|
344
|
+
}
|
345
|
+
if (options.optimization.runtimeChunk) {
|
326
346
|
new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
|
327
|
-
|
347
|
+
}
|
348
|
+
if (options.optimization.noEmitOnErrors) {
|
328
349
|
new NoEmitOnErrorsPlugin().apply(compiler);
|
329
|
-
|
350
|
+
}
|
351
|
+
if (options.optimization.checkWasmTypes) {
|
352
|
+
new WasmFinalizeExportsPlugin().apply(compiler);
|
353
|
+
}
|
354
|
+
if (options.optimization.namedModules) {
|
330
355
|
new NamedModulesPlugin().apply(compiler);
|
331
|
-
|
356
|
+
}
|
357
|
+
if (options.optimization.namedChunks) {
|
332
358
|
new NamedChunksPlugin().apply(compiler);
|
359
|
+
}
|
333
360
|
if (options.optimization.nodeEnv) {
|
334
361
|
new DefinePlugin({
|
335
362
|
"process.env.NODE_ENV": JSON.stringify(options.optimization.nodeEnv)
|
@@ -354,15 +381,16 @@ class WebpackOptionsApply extends OptionsApply {
|
|
354
381
|
new WarnCaseSensitiveModulesPlugin().apply(compiler);
|
355
382
|
|
356
383
|
if (options.cache) {
|
357
|
-
|
384
|
+
const CachePlugin = require("./CachePlugin");
|
358
385
|
new CachePlugin(
|
359
386
|
typeof options.cache === "object" ? options.cache : null
|
360
387
|
).apply(compiler);
|
361
388
|
}
|
362
389
|
|
363
390
|
compiler.hooks.afterPlugins.call(compiler);
|
364
|
-
if (!compiler.inputFileSystem)
|
391
|
+
if (!compiler.inputFileSystem) {
|
365
392
|
throw new Error("No input filesystem provided");
|
393
|
+
}
|
366
394
|
compiler.resolverFactory.hooks.resolveOptions
|
367
395
|
.for("normal")
|
368
396
|
.tap("WebpackOptionsApply", resolveOptions => {
|
@@ -136,10 +136,11 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
136
136
|
}
|
137
137
|
});
|
138
138
|
this.set("output.devtoolNamespace", "make", options => {
|
139
|
-
if (Array.isArray(options.output.library))
|
139
|
+
if (Array.isArray(options.output.library)) {
|
140
140
|
return options.output.library.join(".");
|
141
|
-
else if (typeof options.output.library === "object")
|
141
|
+
} else if (typeof options.output.library === "object") {
|
142
142
|
return options.output.library.root || "";
|
143
|
+
}
|
143
144
|
return options.output.library || "";
|
144
145
|
});
|
145
146
|
this.set("output.libraryTarget", "var");
|
@@ -253,6 +254,10 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
253
254
|
this.set("optimization.noEmitOnErrors", "make", options =>
|
254
255
|
isProductionLikeMode(options)
|
255
256
|
);
|
257
|
+
this.set("optimization.checkWasmTypes", "make", options =>
|
258
|
+
isProductionLikeMode(options)
|
259
|
+
);
|
260
|
+
this.set("optimization.mangleWasmImports", false);
|
256
261
|
this.set(
|
257
262
|
"optimization.namedModules",
|
258
263
|
"make",
|
@@ -293,11 +298,10 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
293
298
|
}
|
294
299
|
}
|
295
300
|
]);
|
296
|
-
this.set(
|
297
|
-
|
298
|
-
"
|
299
|
-
|
300
|
-
);
|
301
|
+
this.set("optimization.nodeEnv", "make", options => {
|
302
|
+
// TODO: In webpack 5, it should return `false` when mode is `none`
|
303
|
+
return options.mode || "production";
|
304
|
+
});
|
301
305
|
|
302
306
|
this.set("resolve", "call", value => Object.assign({}, value));
|
303
307
|
this.set("resolve.unsafeCache", true);
|
@@ -305,9 +309,11 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
305
309
|
this.set("resolve.extensions", [".wasm", ".mjs", ".js", ".json"]);
|
306
310
|
this.set("resolve.mainFiles", ["index"]);
|
307
311
|
this.set("resolve.aliasFields", "make", options => {
|
308
|
-
if (options.target === "web" || options.target === "webworker")
|
312
|
+
if (options.target === "web" || options.target === "webworker") {
|
309
313
|
return ["browser"];
|
310
|
-
else
|
314
|
+
} else {
|
315
|
+
return [];
|
316
|
+
}
|
311
317
|
});
|
312
318
|
this.set("resolve.mainFields", "make", options => {
|
313
319
|
if (
|