webpack 4.1.0 → 4.4.0

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