Skip to content

Commit 37f7681

Browse files
authored
Merge pull request webpack#6697 from webpack/bugfix/split-chunks
fix bug where modules are put into the wrong chunk
2 parents 8a59ef7 + 4d68350 commit 37f7681

File tree

8 files changed

+58
-0
lines changed

8 files changed

+58
-0
lines changed

lib/optimize/SplitChunksPlugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ module.exports = class SplitChunksPlugin {
304304
chunk => !chunk.canBeInitial()
305305
)
306306
: Array.from(chunkCombination);
307+
// Break if minimum number of chunks is not reached
308+
if (selectedChunks.length < cacheGroup.minChunks) continue;
307309
// Determine name for split chunk
308310
const name = cacheGroup.getName(
309311
module,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "x";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "x";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Entrypoint main = vendors.js main.js
2+
chunk {0} async-a.js (async-a) 32 bytes <{2}> <{3}> [rendered]
3+
> ./a [3] ./index.js 2:0-47
4+
[0] ./node_modules/x.js 20 bytes {0} {1} [built]
5+
[1] ./a.js 12 bytes {0} [built]
6+
chunk {1} async-b.js (async-b) 32 bytes <{2}> <{3}> [rendered]
7+
> ./b [3] ./index.js 3:0-47
8+
[0] ./node_modules/x.js 20 bytes {0} {1} [built]
9+
[2] ./b.js 12 bytes {1} [built]
10+
chunk {2} main.js (main) 110 bytes ={3}= >{0}< >{1}< [entry] [rendered]
11+
> ./ main
12+
[3] ./index.js 110 bytes {2} [built]
13+
chunk {3} vendors.js (vendors) 20 bytes ={2}= >{0}< >{1}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors)
14+
> ./ main
15+
[4] ./node_modules/y.js 20 bytes {3} [built]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "y";
2+
import(/* webpackChunkName: "async-a" */ "./a");
3+
import(/* webpackChunkName: "async-b" */ "./b");

test/statsCases/split-chunks-issue-6696/node_modules/x.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/statsCases/split-chunks-issue-6696/node_modules/y.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const stats = {
2+
hash: false,
3+
timings: false,
4+
builtAt: false,
5+
assets: false,
6+
chunks: true,
7+
chunkOrigins: true,
8+
entrypoints: true,
9+
modules: false
10+
};
11+
module.exports = {
12+
name: "default",
13+
mode: "production",
14+
entry: {
15+
main: "./"
16+
},
17+
output: {
18+
filename: "[name].js"
19+
},
20+
optimization: {
21+
splitChunks: {
22+
cacheGroups: {
23+
default: false,
24+
vendors: {
25+
test: /[\\/]node_modules[\\/]/,
26+
chunks: "initial",
27+
enforce: true,
28+
name: "vendors"
29+
}
30+
}
31+
}
32+
},
33+
stats
34+
};

0 commit comments

Comments
 (0)