Skip to content

Commit 907cd16

Browse files
committed
fix a bug that prevented the automatic chunk selection to select initial chunks
fixes webpack#5145 fixes webpack#5386 fixes webpack#5285 fixes webpack#5109
1 parent a15d4a9 commit 907cd16

File tree

18 files changed

+160
-2
lines changed

18 files changed

+160
-2
lines changed

lib/optimize/CommonsChunkPlugin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ You can however specify the name of the async chunk by passing the desired strin
201201

202202
// we dont have named chunks specified, so we just take all of them
203203
if(asyncOrNoSelectedChunk) {
204-
return allChunks.filter(chunk => !chunk.isInitial());
204+
return allChunks;
205205
}
206206

207207
/**
@@ -229,8 +229,15 @@ Take a look at the "name"/"names" or async/children option.`);
229229
}
230230

231231
return targetChunk.chunks.filter((chunk) => {
232+
// we only are interested in on-demand chunks
233+
if(chunk.isInitial())
234+
return false;
235+
232236
// we can only move modules from this chunk if the "commonChunk" is the only parent
233-
return asyncOption || chunk.parents.length === 1;
237+
if(!asyncOption)
238+
return chunk.parents.length === 1;
239+
240+
return true;
234241
});
235242
}
236243

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "c";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
it("should load the full async commons", function(done) {
2+
require.ensure(["./a"], function(require) {
3+
require("./a").should.be.eql("a");
4+
done();
5+
});
6+
});
7+
8+
it("should load a chunk with async commons (AMD)", function(done) {
9+
require(["./a", "./b"], function(a, b) {
10+
a.should.be.eql("a");
11+
b.should.be.eql("b");
12+
done();
13+
});
14+
});
15+
16+
it("should load a chunk with async commons (require.ensure)", function(done) {
17+
require.ensure([], function(require) {
18+
require("./a").should.be.eql("a");
19+
require("./c").should.be.eql("c");
20+
done();
21+
});
22+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var webpack = require("../../../../");
2+
3+
module.exports = {
4+
plugins: [
5+
new webpack.optimize.CommonsChunkPlugin({
6+
async: true
7+
})
8+
]
9+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "c";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
chunk {0} 0.js 21 bytes {3} [rendered]
2+
> async commons [1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js 2:1-5:3
3+
> async commons [1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js 9:1-13:3
4+
> async commons [1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js 17:1-21:3
5+
[0] (webpack)/test/statsCases/async-commons-chunk-all-selected/a.js 21 bytes {0} [built]
6+
chunk {1} 1.js 21 bytes {3} [rendered]
7+
> [1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js 17:1-21:3
8+
[3] (webpack)/test/statsCases/async-commons-chunk-all-selected/c.js 21 bytes {1} [built]
9+
chunk {2} 2.js 21 bytes {3} [rendered]
10+
> [1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js 9:1-13:3
11+
[2] (webpack)/test/statsCases/async-commons-chunk-all-selected/b.js 21 bytes {2} [built]
12+
chunk {3} entry.js (entry) 550 bytes [entry] [rendered]
13+
> entry [1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js
14+
[1] (webpack)/test/statsCases/async-commons-chunk-all-selected/index.js 550 bytes {3} [built]

0 commit comments

Comments
 (0)