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.
- package/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,317 +1,337 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const path = require("path");
|
8
|
-
|
9
|
-
const OptionsDefaulter = require("./OptionsDefaulter");
|
10
|
-
const Template = require("./Template");
|
11
|
-
|
12
|
-
const isProductionLikeMode = options => {
|
13
|
-
return options.mode === "production" || !options.mode;
|
14
|
-
};
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
this.set("
|
34
|
-
this.set("
|
35
|
-
|
36
|
-
this.set("module
|
37
|
-
this.set("module.
|
38
|
-
this.set("module.
|
39
|
-
this.set("module.
|
40
|
-
this.set("module.
|
41
|
-
this.set("module.
|
42
|
-
this.set("module.
|
43
|
-
this.set("module.
|
44
|
-
this.set("module.
|
45
|
-
this.set("module.
|
46
|
-
this.set("module.
|
47
|
-
this.set("module.
|
48
|
-
this.set("module.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
return
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
case "
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
this.set("output.
|
146
|
-
this.set("output.
|
147
|
-
this.set(
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
this.set("
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
this.set("
|
160
|
-
this.set("
|
161
|
-
this.set("
|
162
|
-
this.set("
|
163
|
-
|
164
|
-
this.set("node
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
);
|
172
|
-
this.set("
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
this.set("performance
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
this.set("
|
189
|
-
this.set("
|
190
|
-
this.set(
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
this.set("optimization.
|
197
|
-
|
198
|
-
);
|
199
|
-
this.set("optimization.
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
this.set("optimization.
|
209
|
-
this.set("optimization.
|
210
|
-
|
211
|
-
|
212
|
-
this.set("optimization.
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
this.set("optimization.splitChunks.
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
this.set("optimization.
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
options
|
248
|
-
);
|
249
|
-
this.set(
|
250
|
-
"optimization.
|
251
|
-
"make",
|
252
|
-
options =>
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
);
|
259
|
-
this.set(
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
});
|
296
|
-
this.set("resolve.
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
this.set("
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const path = require("path");
|
8
|
+
|
9
|
+
const OptionsDefaulter = require("./OptionsDefaulter");
|
10
|
+
const Template = require("./Template");
|
11
|
+
|
12
|
+
const isProductionLikeMode = options => {
|
13
|
+
return options.mode === "production" || !options.mode;
|
14
|
+
};
|
15
|
+
|
16
|
+
const isWebLikeTarget = options => {
|
17
|
+
return options.target === "web" || options.target === "webworker";
|
18
|
+
};
|
19
|
+
|
20
|
+
class WebpackOptionsDefaulter extends OptionsDefaulter {
|
21
|
+
constructor() {
|
22
|
+
super();
|
23
|
+
|
24
|
+
this.set("entry", "./src");
|
25
|
+
|
26
|
+
this.set(
|
27
|
+
"devtool",
|
28
|
+
"make",
|
29
|
+
options => (options.mode === "development" ? "eval" : false)
|
30
|
+
);
|
31
|
+
this.set("cache", "make", options => options.mode === "development");
|
32
|
+
|
33
|
+
this.set("context", process.cwd());
|
34
|
+
this.set("target", "web");
|
35
|
+
|
36
|
+
this.set("module", "call", value => Object.assign({}, value));
|
37
|
+
this.set("module.unknownContextRequest", ".");
|
38
|
+
this.set("module.unknownContextRegExp", false);
|
39
|
+
this.set("module.unknownContextRecursive", true);
|
40
|
+
this.set("module.unknownContextCritical", true);
|
41
|
+
this.set("module.exprContextRequest", ".");
|
42
|
+
this.set("module.exprContextRegExp", false);
|
43
|
+
this.set("module.exprContextRecursive", true);
|
44
|
+
this.set("module.exprContextCritical", true);
|
45
|
+
this.set("module.wrappedContextRegExp", /.*/);
|
46
|
+
this.set("module.wrappedContextRecursive", true);
|
47
|
+
this.set("module.wrappedContextCritical", false);
|
48
|
+
this.set("module.strictExportPresence", false);
|
49
|
+
this.set("module.strictThisContextOnImports", false);
|
50
|
+
this.set("module.unsafeCache", "make", options => !!options.cache);
|
51
|
+
this.set("module.rules", []);
|
52
|
+
this.set("module.defaultRules", "make", options => [
|
53
|
+
{
|
54
|
+
type: "javascript/auto",
|
55
|
+
resolve: {}
|
56
|
+
},
|
57
|
+
{
|
58
|
+
test: /\.mjs$/i,
|
59
|
+
type: "javascript/esm",
|
60
|
+
resolve: {
|
61
|
+
mainFields:
|
62
|
+
options.target === "web" ||
|
63
|
+
options.target === "webworker" ||
|
64
|
+
options.target === "electron-renderer"
|
65
|
+
? ["browser", "main"]
|
66
|
+
: ["main"]
|
67
|
+
}
|
68
|
+
},
|
69
|
+
{
|
70
|
+
test: /\.json$/i,
|
71
|
+
type: "json"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
test: /\.wasm$/i,
|
75
|
+
type: "webassembly/experimental"
|
76
|
+
}
|
77
|
+
]);
|
78
|
+
|
79
|
+
this.set("output", "call", (value, options) => {
|
80
|
+
if (typeof value === "string") {
|
81
|
+
return {
|
82
|
+
filename: value
|
83
|
+
};
|
84
|
+
} else if (typeof value !== "object") {
|
85
|
+
return {};
|
86
|
+
} else {
|
87
|
+
return Object.assign({}, value);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
|
91
|
+
this.set("output.filename", "[name].js");
|
92
|
+
this.set("output.chunkFilename", "make", options => {
|
93
|
+
const filename = options.output.filename;
|
94
|
+
if (typeof filename !== "function") {
|
95
|
+
const hasName = filename.includes("[name]");
|
96
|
+
const hasId = filename.includes("[id]");
|
97
|
+
const hasChunkHash = filename.includes("[chunkhash]");
|
98
|
+
// Anything changing depending on chunk is fine
|
99
|
+
if (hasChunkHash || hasName || hasId) return filename;
|
100
|
+
// Elsewise prefix "[id]." in front of the basename to make it changing
|
101
|
+
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
|
102
|
+
}
|
103
|
+
return "[id].js";
|
104
|
+
});
|
105
|
+
this.set("output.webassemblyModuleFilename", "[modulehash].module.wasm");
|
106
|
+
this.set("output.library", "");
|
107
|
+
this.set("output.hotUpdateFunction", "make", options => {
|
108
|
+
return Template.toIdentifier(
|
109
|
+
"webpackHotUpdate" + Template.toIdentifier(options.output.library)
|
110
|
+
);
|
111
|
+
});
|
112
|
+
this.set("output.jsonpFunction", "make", options => {
|
113
|
+
return Template.toIdentifier(
|
114
|
+
"webpackJsonp" + Template.toIdentifier(options.output.library)
|
115
|
+
);
|
116
|
+
});
|
117
|
+
this.set("output.chunkCallbackName", "make", options => {
|
118
|
+
return Template.toIdentifier(
|
119
|
+
"webpackChunk" + Template.toIdentifier(options.output.library)
|
120
|
+
);
|
121
|
+
});
|
122
|
+
this.set("output.globalObject", "make", options => {
|
123
|
+
switch (options.target) {
|
124
|
+
case "web":
|
125
|
+
case "electron-renderer":
|
126
|
+
return "window";
|
127
|
+
case "webworker":
|
128
|
+
return "self";
|
129
|
+
case "node":
|
130
|
+
case "async-node":
|
131
|
+
case "node-webkit":
|
132
|
+
case "electron-main":
|
133
|
+
return "global";
|
134
|
+
default:
|
135
|
+
return "self";
|
136
|
+
}
|
137
|
+
});
|
138
|
+
this.set("output.devtoolNamespace", "make", options => {
|
139
|
+
if (Array.isArray(options.output.library))
|
140
|
+
return options.output.library.join(".");
|
141
|
+
else if (typeof options.output.library === "object")
|
142
|
+
return options.output.library.root || "";
|
143
|
+
return options.output.library || "";
|
144
|
+
});
|
145
|
+
this.set("output.libraryTarget", "var");
|
146
|
+
this.set("output.path", path.join(process.cwd(), "dist"));
|
147
|
+
this.set(
|
148
|
+
"output.pathinfo",
|
149
|
+
"make",
|
150
|
+
options => options.mode === "development"
|
151
|
+
);
|
152
|
+
this.set("output.sourceMapFilename", "[file].map[query]");
|
153
|
+
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
|
154
|
+
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
|
155
|
+
this.set("output.crossOriginLoading", false);
|
156
|
+
this.set("output.jsonpScriptType", false);
|
157
|
+
this.set("output.chunkLoadTimeout", 120000);
|
158
|
+
this.set("output.hashFunction", "md4");
|
159
|
+
this.set("output.hashDigest", "hex");
|
160
|
+
this.set("output.hashDigestLength", 20);
|
161
|
+
this.set("output.devtoolLineToLine", false);
|
162
|
+
this.set("output.strictModuleExceptionHandling", false);
|
163
|
+
|
164
|
+
this.set("node", "call", value => {
|
165
|
+
if (typeof value === "boolean") {
|
166
|
+
return value;
|
167
|
+
} else {
|
168
|
+
return Object.assign({}, value);
|
169
|
+
}
|
170
|
+
});
|
171
|
+
this.set("node.console", false);
|
172
|
+
this.set("node.process", true);
|
173
|
+
this.set("node.global", true);
|
174
|
+
this.set("node.Buffer", true);
|
175
|
+
this.set("node.setImmediate", true);
|
176
|
+
this.set("node.__filename", "mock");
|
177
|
+
this.set("node.__dirname", "mock");
|
178
|
+
|
179
|
+
this.set("performance", "call", (value, options) => {
|
180
|
+
if (value === false) return false;
|
181
|
+
if (
|
182
|
+
value === undefined &&
|
183
|
+
(!isProductionLikeMode(options) || !isWebLikeTarget(options))
|
184
|
+
)
|
185
|
+
return false;
|
186
|
+
return Object.assign({}, value);
|
187
|
+
});
|
188
|
+
this.set("performance.maxAssetSize", 250000);
|
189
|
+
this.set("performance.maxEntrypointSize", 250000);
|
190
|
+
this.set(
|
191
|
+
"performance.hints",
|
192
|
+
"make",
|
193
|
+
options => (isProductionLikeMode(options) ? "warning" : false)
|
194
|
+
);
|
195
|
+
|
196
|
+
this.set("optimization.removeAvailableModules", true);
|
197
|
+
this.set("optimization.removeEmptyChunks", true);
|
198
|
+
this.set("optimization.mergeDuplicateChunks", true);
|
199
|
+
this.set("optimization.flagIncludedChunks", "make", options =>
|
200
|
+
isProductionLikeMode(options)
|
201
|
+
);
|
202
|
+
this.set("optimization.occurrenceOrder", "make", options =>
|
203
|
+
isProductionLikeMode(options)
|
204
|
+
);
|
205
|
+
this.set("optimization.sideEffects", "make", options =>
|
206
|
+
isProductionLikeMode(options)
|
207
|
+
);
|
208
|
+
this.set("optimization.providedExports", true);
|
209
|
+
this.set("optimization.usedExports", "make", options =>
|
210
|
+
isProductionLikeMode(options)
|
211
|
+
);
|
212
|
+
this.set("optimization.concatenateModules", "make", options =>
|
213
|
+
isProductionLikeMode(options)
|
214
|
+
);
|
215
|
+
this.set("optimization.splitChunks", {});
|
216
|
+
this.set("optimization.splitChunks.chunks", "async");
|
217
|
+
this.set("optimization.splitChunks.minSize", 30000);
|
218
|
+
this.set("optimization.splitChunks.minChunks", 1);
|
219
|
+
this.set("optimization.splitChunks.maxAsyncRequests", 5);
|
220
|
+
this.set("optimization.splitChunks.automaticNameDelimiter", "~");
|
221
|
+
this.set("optimization.splitChunks.maxInitialRequests", 3);
|
222
|
+
this.set("optimization.splitChunks.name", true);
|
223
|
+
this.set("optimization.splitChunks.cacheGroups", {});
|
224
|
+
this.set("optimization.splitChunks.cacheGroups.default", {
|
225
|
+
reuseExistingChunk: true,
|
226
|
+
minChunks: 2,
|
227
|
+
priority: -20
|
228
|
+
});
|
229
|
+
this.set("optimization.splitChunks.cacheGroups.vendors", {
|
230
|
+
test: /[\\/]node_modules[\\/]/,
|
231
|
+
priority: -10
|
232
|
+
});
|
233
|
+
this.set("optimization.runtimeChunk", "call", value => {
|
234
|
+
if (value === "single") {
|
235
|
+
return {
|
236
|
+
name: "runtime"
|
237
|
+
};
|
238
|
+
}
|
239
|
+
if (value === true || value === "multiple") {
|
240
|
+
return {
|
241
|
+
name: entrypoint => `runtime~${entrypoint.name}`
|
242
|
+
};
|
243
|
+
}
|
244
|
+
return value;
|
245
|
+
});
|
246
|
+
this.set("optimization.noEmitOnErrors", "make", options =>
|
247
|
+
isProductionLikeMode(options)
|
248
|
+
);
|
249
|
+
this.set(
|
250
|
+
"optimization.namedModules",
|
251
|
+
"make",
|
252
|
+
options => options.mode === "development"
|
253
|
+
);
|
254
|
+
this.set(
|
255
|
+
"optimization.namedChunks",
|
256
|
+
"make",
|
257
|
+
options => options.mode === "development"
|
258
|
+
);
|
259
|
+
this.set(
|
260
|
+
"optimization.portableRecords",
|
261
|
+
"make",
|
262
|
+
options =>
|
263
|
+
!!(
|
264
|
+
options.recordsInputPath ||
|
265
|
+
options.recordsOutputPath ||
|
266
|
+
options.recordsPath
|
267
|
+
)
|
268
|
+
);
|
269
|
+
this.set("optimization.minimize", "make", options =>
|
270
|
+
isProductionLikeMode(options)
|
271
|
+
);
|
272
|
+
this.set("optimization.minimizer", "make", options => [
|
273
|
+
{
|
274
|
+
apply: compiler => {
|
275
|
+
// Lazy load the uglifyjs plugin
|
276
|
+
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
277
|
+
const SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
|
278
|
+
new UglifyJsPlugin({
|
279
|
+
cache: true,
|
280
|
+
parallel: true,
|
281
|
+
sourceMap:
|
282
|
+
(options.devtool && /source-?map/.test(options.devtool)) ||
|
283
|
+
(options.plugins &&
|
284
|
+
options.plugins.some(p => p instanceof SourceMapDevToolPlugin))
|
285
|
+
}).apply(compiler);
|
286
|
+
}
|
287
|
+
}
|
288
|
+
]);
|
289
|
+
this.set(
|
290
|
+
"optimization.nodeEnv",
|
291
|
+
"make",
|
292
|
+
options => options.mode || "production"
|
293
|
+
);
|
294
|
+
|
295
|
+
this.set("resolve", "call", value => Object.assign({}, value));
|
296
|
+
this.set("resolve.unsafeCache", true);
|
297
|
+
this.set("resolve.modules", ["node_modules"]);
|
298
|
+
this.set("resolve.extensions", [".wasm", ".mjs", ".js", ".json"]);
|
299
|
+
this.set("resolve.mainFiles", ["index"]);
|
300
|
+
this.set("resolve.aliasFields", "make", options => {
|
301
|
+
if (options.target === "web" || options.target === "webworker")
|
302
|
+
return ["browser"];
|
303
|
+
else return [];
|
304
|
+
});
|
305
|
+
this.set("resolve.mainFields", "make", options => {
|
306
|
+
if (
|
307
|
+
options.target === "web" ||
|
308
|
+
options.target === "webworker" ||
|
309
|
+
options.target === "electron-renderer"
|
310
|
+
) {
|
311
|
+
return ["browser", "module", "main"];
|
312
|
+
} else {
|
313
|
+
return ["module", "main"];
|
314
|
+
}
|
315
|
+
});
|
316
|
+
this.set("resolve.cacheWithContext", "make", options => {
|
317
|
+
return (
|
318
|
+
Array.isArray(options.resolve.plugins) &&
|
319
|
+
options.resolve.plugins.length > 0
|
320
|
+
);
|
321
|
+
});
|
322
|
+
|
323
|
+
this.set("resolveLoader", "call", value => Object.assign({}, value));
|
324
|
+
this.set("resolveLoader.unsafeCache", true);
|
325
|
+
this.set("resolveLoader.mainFields", ["loader", "main"]);
|
326
|
+
this.set("resolveLoader.extensions", [".js", ".json"]);
|
327
|
+
this.set("resolveLoader.mainFiles", ["index"]);
|
328
|
+
this.set("resolveLoader.cacheWithContext", "make", options => {
|
329
|
+
return (
|
330
|
+
Array.isArray(options.resolveLoader.plugins) &&
|
331
|
+
options.resolveLoader.plugins.length > 0
|
332
|
+
);
|
333
|
+
});
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
module.exports = WebpackOptionsDefaulter;
|