|
6 | 6 | "use strict";
|
7 | 7 |
|
8 | 8 | const path = require("path");
|
9 |
| - |
10 | 9 | const OptionsDefaulter = require("./OptionsDefaulter");
|
11 | 10 | const Template = require("./Template");
|
12 | 11 |
|
| 12 | +const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i; |
| 13 | + |
13 | 14 | const isProductionLikeMode = options => {
|
14 | 15 | return options.mode === "production" || !options.mode;
|
15 | 16 | };
|
@@ -78,7 +79,14 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
78 | 79 | this.set("module.wrappedContextCritical", false);
|
79 | 80 | this.set("module.strictExportPresence", false);
|
80 | 81 | this.set("module.strictThisContextOnImports", false);
|
81 |
| - this.set("module.unsafeCache", "make", options => !!options.cache); |
| 82 | + this.set("module.unsafeCache", "make", options => { |
| 83 | + if (options.cache) { |
| 84 | + return module => { |
| 85 | + const name = module.nameForCondition(); |
| 86 | + return name && NODE_MODULES_REGEXP.test(name); |
| 87 | + }; |
| 88 | + } |
| 89 | + }); |
82 | 90 | this.set("module.rules", []);
|
83 | 91 | this.set("module.defaultRules", "make", options => [
|
84 | 92 | {
|
@@ -273,7 +281,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
273 | 281 | });
|
274 | 282 | this.set("optimization.splitChunks.cacheGroups.defaultVendors", {
|
275 | 283 | automaticNamePrefix: "vendors",
|
276 |
| - test: /[\\/]node_modules[\\/]/, |
| 284 | + test: NODE_MODULES_REGEXP, |
277 | 285 | priority: -10
|
278 | 286 | });
|
279 | 287 | this.set("optimization.runtimeChunk", "call", value => {
|
@@ -360,24 +368,11 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
360 | 368 | return ["module", "main"];
|
361 | 369 | }
|
362 | 370 | });
|
363 |
| - this.set("resolve.cacheWithContext", "make", options => { |
364 |
| - return ( |
365 |
| - Array.isArray(options.resolve.plugins) && |
366 |
| - options.resolve.plugins.length > 0 |
367 |
| - ); |
368 |
| - }); |
369 | 371 |
|
370 | 372 | this.set("resolveLoader", "call", value => Object.assign({}, value));
|
371 |
| - this.set("resolveLoader.unsafeCache", true); |
372 | 373 | this.set("resolveLoader.mainFields", ["loader", "main"]);
|
373 | 374 | this.set("resolveLoader.extensions", [".js", ".json"]);
|
374 | 375 | this.set("resolveLoader.mainFiles", ["index"]);
|
375 |
| - this.set("resolveLoader.cacheWithContext", "make", options => { |
376 |
| - return ( |
377 |
| - Array.isArray(options.resolveLoader.plugins) && |
378 |
| - options.resolveLoader.plugins.length > 0 |
379 |
| - ); |
380 |
| - }); |
381 | 376 | }
|
382 | 377 | }
|
383 | 378 |
|
|
0 commit comments