Skip to content

Commit

Permalink
fix bug where modules are put into the wrong chunk
Browse files Browse the repository at this point in the history
fixes #6696
  • Loading branch information
sokra committed Mar 7, 2018
1 parent 8a59ef7 commit 4d68350
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/optimize/SplitChunksPlugin.js
Expand Up @@ -304,6 +304,8 @@ module.exports = class SplitChunksPlugin {
chunk => !chunk.canBeInitial()
)
: Array.from(chunkCombination);
// Break if minimum number of chunks is not reached
if (selectedChunks.length < cacheGroup.minChunks) continue;
// Determine name for split chunk
const name = cacheGroup.getName(
module,
Expand Down
1 change: 1 addition & 0 deletions test/statsCases/split-chunks-issue-6696/a.js
@@ -0,0 +1 @@
import "x";
1 change: 1 addition & 0 deletions test/statsCases/split-chunks-issue-6696/b.js
@@ -0,0 +1 @@
import "x";
15 changes: 15 additions & 0 deletions test/statsCases/split-chunks-issue-6696/expected.txt
@@ -0,0 +1,15 @@
Entrypoint main = vendors.js main.js
chunk {0} async-a.js (async-a) 32 bytes <{2}> <{3}> [rendered]
> ./a [3] ./index.js 2:0-47
[0] ./node_modules/x.js 20 bytes {0} {1} [built]
[1] ./a.js 12 bytes {0} [built]
chunk {1} async-b.js (async-b) 32 bytes <{2}> <{3}> [rendered]
> ./b [3] ./index.js 3:0-47
[0] ./node_modules/x.js 20 bytes {0} {1} [built]
[2] ./b.js 12 bytes {1} [built]
chunk {2} main.js (main) 110 bytes ={3}= >{0}< >{1}< [entry] [rendered]
> ./ main
[3] ./index.js 110 bytes {2} [built]
chunk {3} vendors.js (vendors) 20 bytes ={2}= >{0}< >{1}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors)
> ./ main
[4] ./node_modules/y.js 20 bytes {3} [built]
3 changes: 3 additions & 0 deletions test/statsCases/split-chunks-issue-6696/index.js
@@ -0,0 +1,3 @@
import "y";
import(/* webpackChunkName: "async-a" */ "./a");
import(/* webpackChunkName: "async-b" */ "./b");
1 change: 1 addition & 0 deletions test/statsCases/split-chunks-issue-6696/node_modules/x.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/statsCases/split-chunks-issue-6696/node_modules/y.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions test/statsCases/split-chunks-issue-6696/webpack.config.js
@@ -0,0 +1,34 @@
const stats = {
hash: false,
timings: false,
builtAt: false,
assets: false,
chunks: true,
chunkOrigins: true,
entrypoints: true,
modules: false
};
module.exports = {
name: "default",
mode: "production",
entry: {
main: "./"
},
output: {
filename: "[name].js"
},
optimization: {
splitChunks: {
cacheGroups: {
default: false,
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: "initial",
enforce: true,
name: "vendors"
}
}
}
},
stats
};

0 comments on commit 4d68350

Please sign in to comment.