Skip to content

Commit 120de91

Browse files
authored
Merge pull request webpack#4989 from restrry/issue-4980
changing importing order for named and default exports affects common chunk chunkhash
2 parents 8ad6d27 + e030961 commit 120de91

9 files changed

Lines changed: 85 additions & 0 deletions

File tree

lib/Module.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class Module extends DependenciesBlock {
162162
super.sortItems();
163163
this.chunks.sort(byId);
164164
this.reasons.sort((a, b) => byId(a.module, b.module));
165+
if(Array.isArray(this.usedExports)) {
166+
this.usedExports.sort();
167+
}
165168
}
166169

167170
unbuild() {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const a = "a";
2+
export const b = "b";
3+
export const c = "c";
4+
5+
export default "d";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import subA from './submodule-a';
2+
import subB from './submodule-b'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import subB from './submodule-a'
2+
import subC from './submodule-c';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Hash: 7d3a56317b2e339b1d822897fe6052020598632c
2+
Child
3+
Hash: 7d3a56317b2e339b1d82
4+
Time: Xms
5+
Asset Size Chunks Chunk Names
6+
app.js 1.27 kB 0 [emitted] app
7+
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
8+
runtime.js 5.94 kB 2 [emitted] runtime
9+
chunk {0} app.js (app) 185 bytes {1} [initial] [rendered]
10+
[./entry-1.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-1.js 67 bytes {0} [built]
11+
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
12+
[./submodule-b.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-b.js 59 bytes {0} [built]
13+
chunk {1} vendor.bd2b4219dfda1a951495.js (vendor) 87 bytes {2} [initial] [rendered]
14+
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
15+
chunk {2} runtime.js (runtime) 0 bytes [entry] [rendered]
16+
Child
17+
Hash: 2897fe6052020598632c
18+
Time: Xms
19+
Asset Size Chunks Chunk Names
20+
app.js 1.32 kB 0 [emitted] app
21+
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
22+
runtime.js 5.94 kB 2 [emitted] runtime
23+
chunk {0} app.js (app) 192 bytes {1} [initial] [rendered]
24+
[./entry-2.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-2.js 67 bytes {0} [built]
25+
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
26+
[./submodule-c.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-c.js 66 bytes {0} [built]
27+
chunk {1} vendor.bd2b4219dfda1a951495.js (vendor) 87 bytes {2} [initial] [rendered]
28+
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
29+
chunk {2} runtime.js (runtime) 0 bytes [entry] [rendered]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import d, { a } from './constants';
2+
3+
export default d + a;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { b, c } from './constants';
2+
3+
export default b + c;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { a, b, c } from './constants';
2+
3+
export default a + b + c;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var CommonsChunkPlugin = require("../../../lib/optimize/CommonsChunkPlugin");
2+
var NamedModulesPlugin = require("../../../lib/NamedModulesPlugin");
3+
4+
// should generate vendor chunk with the same chunkhash for both entries
5+
module.exports = [{
6+
entry: {
7+
app: "./entry-1.js"
8+
},
9+
plugins: [
10+
new NamedModulesPlugin(),
11+
new CommonsChunkPlugin({
12+
name: "vendor",
13+
filename: "[name].[chunkhash].js",
14+
minChunks: m => /constants/.test(m.resource)
15+
}),
16+
new CommonsChunkPlugin({
17+
name: "runtime"
18+
})
19+
]
20+
},{
21+
entry: {
22+
app: "./entry-2.js"
23+
},
24+
plugins: [
25+
new NamedModulesPlugin(),
26+
new CommonsChunkPlugin({
27+
name: "vendor",
28+
filename: "[name].[chunkhash].js",
29+
minChunks: m => /constants/.test(m.resource)
30+
}),
31+
new CommonsChunkPlugin({
32+
name: "runtime"
33+
})
34+
]
35+
}];

0 commit comments

Comments
 (0)