Skip to content

Commit fe80339

Browse files
committed
use - instead of ~ as default for better compat
fix automaticNameDelimiter in splitChunks fix test cases
1 parent 8281667 commit fe80339

File tree

14 files changed

+437
-424
lines changed

14 files changed

+437
-424
lines changed

lib/WebpackOptionsDefaulter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
267267
this.set("optimization.splitChunks.maxAsyncRequests", "make", options => {
268268
return isProductionLikeMode(options) ? 6 : Infinity;
269269
});
270-
this.set("optimization.splitChunks.automaticNameDelimiter", "~");
270+
this.set("optimization.splitChunks.automaticNameDelimiter", "-");
271271
this.set("optimization.splitChunks.maxInitialRequests", "make", options => {
272272
return isProductionLikeMode(options) ? 4 : Infinity;
273273
});

lib/ids/NamedChunkIdsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const {
2121

2222
class NamedChunkIdsPlugin {
2323
constructor(options) {
24-
this.delimiter = (options && options.delimiter) || "~";
24+
this.delimiter = (options && options.delimiter) || "-";
2525
this.context = options && options.context;
2626
}
2727

lib/optimize/SplitChunksPlugin.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ module.exports = class SplitChunksPlugin {
288288
maxInitialRequests: option.maxInitialRequests,
289289
filename: option.filename,
290290
idHint: option.idHint,
291+
automaticNameDelimiter: option.automaticNameDelimiter,
291292
reuseExistingChunk: option.reuseExistingChunk
292293
});
293294
}
@@ -748,13 +749,13 @@ module.exports = class SplitChunksPlugin {
748749
});
749750

750751
// Skip when no chunk selected
751-
if (usedChunks.length === 0) continue;
752+
if (usedChunks.length === 0 && !isReused) continue;
752753

753754
if (
754755
Number.isFinite(item.cacheGroup.maxInitialRequests) ||
755756
Number.isFinite(item.cacheGroup.maxAsyncRequests)
756757
) {
757-
const chunkInLimit = usedChunks.filter(chunk => {
758+
const chunksInLimit = usedChunks.filter(chunk => {
758759
// respect max requests when not enforced
759760
const maxRequests = chunk.isOnlyInitial()
760761
? item.cacheGroup.maxInitialRequests
@@ -769,13 +770,15 @@ module.exports = class SplitChunksPlugin {
769770
);
770771
});
771772

772-
if (chunkInLimit.length < usedChunks.length) {
773-
if (chunkInLimit.length >= item.cacheGroup.minChunks) {
773+
if (isReused) chunksInLimit.push(newChunk);
774+
775+
if (chunksInLimit.length < usedChunks.length) {
776+
if (chunksInLimit.length >= item.cacheGroup.minChunks) {
774777
for (const module of item.modules) {
775778
addModuleToChunksInfoMap(
776779
item.cacheGroup,
777-
chunkInLimit,
778-
getKey(chunkInLimit),
780+
chunksInLimit,
781+
getKey(chunksInLimit),
779782
module
780783
);
781784
}

test/__snapshots__/ConfigTestCases.test.js.snap

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ exports[`ConfigTestCases records issue-2991 exported tests should write relative
44
"{
55
\\"chunks\\": {
66
\\"byName\\": {
7-
\\"main\\": 0
7+
\\"main\\": 404
88
},
99
\\"bySource\\": {
1010
},
1111
\\"usedIds\\": [
12-
0
12+
404
1313
]
1414
},
1515
\\"modules\\": {
1616
\\"byIdentifier\\": {
17-
\\"external \\\\\\"fs\\\\\\"\\": 188,
18-
\\"external \\\\\\"path\\\\\\"\\": 158,
19-
\\"ignored pkgs/somepackage/foo\\": 569,
17+
\\"external \\\\\\"fs\\\\\\"\\": 66,
18+
\\"external \\\\\\"path\\\\\\"\\": 589,
19+
\\"ignored pkgs/somepackage/foo\\": 760,
2020
\\"test.js\\": 316
2121
},
2222
\\"usedIds\\": [
23-
158,
24-
188,
23+
66,
2524
316,
26-
569
25+
589,
26+
760
2727
]
2828
}
2929
}"
@@ -33,30 +33,30 @@ exports[`ConfigTestCases records issue-7339 exported tests should write relative
3333
"{
3434
\\"chunks\\": {
3535
\\"byName\\": {
36-
\\"main\\": 0
36+
\\"main\\": 404
3737
},
3838
\\"bySource\\": {
3939
},
4040
\\"usedIds\\": [
41-
0
41+
404
4242
]
4343
},
4444
\\"modules\\": {
4545
\\"byIdentifier\\": {
46-
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 913,
46+
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 154,
4747
\\"dependencies/bar.js\\": 853,
4848
\\"dependencies/foo.js\\": 494,
49-
\\"external \\\\\\"fs\\\\\\"\\": 188,
50-
\\"external \\\\\\"path\\\\\\"\\": 158,
49+
\\"external \\\\\\"fs\\\\\\"\\": 66,
50+
\\"external \\\\\\"path\\\\\\"\\": 589,
5151
\\"test.js\\": 316
5252
},
5353
\\"usedIds\\": [
54-
158,
55-
188,
54+
66,
55+
154,
5656
316,
5757
494,
58-
853,
59-
913
58+
589,
59+
853
6060
]
6161
}
6262
}"

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 379 additions & 383 deletions
Large diffs are not rendered by default.

test/configCases/async-commons-chunk/existing-name/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ module.exports = {
44
},
55
optimization: {
66
splitChunks: {
7-
minSize: 1,
8-
name: true
7+
minSize: 1
98
},
109
chunkIds: "named"
1110
}

test/configCases/hash-length/output-filename/test.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
}, files: ${files.join(", ")})`
4040
);
4141
}
42-
verifyFilenameLength(filename, bundleDetect.expectedNameLength);
42+
verifyFilenameLength(filename.replace(/^\d+\./, "X."), bundleDetect.expectedNameLength);
4343
}
4444

4545
return "./" + filename;

test/configCases/split-chunks/chunk-filename-delimiter-default/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ it("should run", function() {
88
);
99

1010
const files = require("fs").readdirSync(__dirname);
11-
const hasFile = files.indexOf('a~b~c.bundle.js') !== -1;
12-
13-
expect(hasFile).toBe(true);
11+
expect(files).toContain('a-a_js-2a91f0ff.bundle.js');
12+
expect(files).toContain('b-b_js-c441f481.bundle.js');
1413
});

test/configCases/split-chunks/chunk-filename-delimiter-default/webpack.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
mode: "development",
23
entry: {
34
main: "./index"
45
},
@@ -13,7 +14,14 @@ module.exports = {
1314
},
1415
optimization: {
1516
splitChunks: {
16-
minSize: 1
17+
cacheGroups: {
18+
async: {
19+
chunks: "async",
20+
reuseExistingChunk: true,
21+
minSize: 1,
22+
maxSize: 1
23+
}
24+
}
1725
}
1826
}
1927
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
const c = require("./commons");
2+
require("./c");
23

34
module.exports = "b" + c;

0 commit comments

Comments
 (0)