Skip to content

Commit d6f9b75

Browse files
committed
added AggressiveMergingPlugin and example
fixes webpack#162
1 parent 91b7921 commit d6f9b75

11 files changed

Lines changed: 326 additions & 0 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# pageA.js
2+
3+
``` javascript
4+
require(["./common"], function(common) {
5+
common(require("./a"));
6+
});
7+
```
8+
9+
# pageB.js
10+
11+
``` javascript
12+
require(["./common"], function(common) {
13+
common(require("./b"));
14+
});
15+
```
16+
17+
# pageC.js
18+
19+
``` javascript
20+
require(["./common"], function(common) {
21+
common(require("./b"));
22+
});
23+
```
24+
25+
# common.js
26+
27+
a big file...
28+
29+
# webpack.config.js
30+
31+
``` javascript
32+
var path = require("path");
33+
var AggressiveMergingPlugin = require("../../lib/optimize/AggressiveMergingPlugin");
34+
module.exports = {
35+
entry: {
36+
pageA: "./pageA",
37+
pageB: "./pageB",
38+
pageC: "./pageC"
39+
},
40+
output: {
41+
path: path.join(__dirname, "js"),
42+
filename: "[name].bundle.js",
43+
chunkFilename: "[id].chunk.js"
44+
},
45+
plugins: [
46+
new AggressiveMergingPlugin({
47+
minSizeReduce: 1.5,
48+
moveToParents: true
49+
})
50+
]
51+
}
52+
```
53+
54+
# Info
55+
56+
## Uncompressed
57+
58+
```
59+
Hash: 07a5b689b878ca0906e9
60+
Version: webpack 1.0.0-rc1
61+
Time: 88ms
62+
Asset Size Chunks Chunk Names
63+
pageB.bundle.js 3963 0 [emitted] pageB
64+
pageA.bundle.js 3932 0 [emitted] pageA
65+
pageC.bundle.js 3787 0 [emitted] pageC
66+
1.chunk.js 5725 1 [emitted]
67+
2.chunk.js 317 2 [emitted]
68+
chunk {0} pageB.bundle.js (pageB) 92 [rendered]
69+
> pageB [0] ./pageB.js
70+
[0] ./pageB.js 71 {0} [built]
71+
[2] ./b.js 21 {0} {2} [built]
72+
cjs require ./b [0] ./pageB.js 2:8-22
73+
cjs require ./b [0] ./pageC.js 2:17-31
74+
chunk {0} pageA.bundle.js (pageA) 92 [rendered]
75+
> pageA [0] ./pageA.js
76+
[0] ./pageA.js 71 {0} [built]
77+
[1] ./a.js 21 {0} {2} [built]
78+
cjs require ./a [0] ./pageA.js 2:8-22
79+
amd require ./a [0] ./pageC.js 1:0-3:2
80+
chunk {0} pageC.bundle.js (pageC) 70 [rendered]
81+
> pageC [0] ./pageC.js
82+
[0] ./pageC.js 70 {0} [built]
83+
chunk {1} 1.chunk.js 5553 {0} {0} [rendered]
84+
> [0] ./pageA.js 1:0-3:2
85+
> aggressive-merge [0] ./pageB.js 1:0-3:2
86+
[3] ./common.js 5553 {1} [built]
87+
amd require ./common [0] ./pageA.js 1:0-3:2
88+
amd require ./common [0] ./pageB.js 1:0-3:2
89+
chunk {2} 2.chunk.js 42 {0} [rendered]
90+
> [0] ./pageC.js 1:0-3:2
91+
[1] ./a.js 21 {0} {2} [built]
92+
cjs require ./a [0] ./pageA.js 2:8-22
93+
amd require ./a [0] ./pageC.js 1:0-3:2
94+
[2] ./b.js 21 {0} {2} [built]
95+
cjs require ./b [0] ./pageB.js 2:8-22
96+
cjs require ./b [0] ./pageC.js 2:17-31
97+
```
98+
99+
## Minimized (uglify-js, no zip)
100+
101+
```
102+
Hash: 384afad3b82b7d3b3f0d
103+
Version: webpack 1.0.0-rc1
104+
Time: 259ms
105+
Asset Size Chunks Chunk Names
106+
pageB.bundle.js 764 0 [emitted] pageB
107+
pageA.bundle.js 763 0 [emitted] pageA
108+
pageC.bundle.js 748 0 [emitted] pageC
109+
1.chunk.js 73 1 [emitted]
110+
2.chunk.js 75 2 [emitted]
111+
chunk {0} pageB.bundle.js (pageB) 92 [rendered]
112+
> pageB [0] ./pageB.js
113+
[0] ./pageB.js 71 {0} [built]
114+
[2] ./b.js 21 {0} {2} [built]
115+
cjs require ./b [0] ./pageB.js 2:8-22
116+
cjs require ./b [0] ./pageC.js 2:17-31
117+
chunk {0} pageA.bundle.js (pageA) 92 [rendered]
118+
> pageA [0] ./pageA.js
119+
[0] ./pageA.js 71 {0} [built]
120+
[1] ./a.js 21 {0} {2} [built]
121+
cjs require ./a [0] ./pageA.js 2:8-22
122+
amd require ./a [0] ./pageC.js 1:0-3:2
123+
chunk {0} pageC.bundle.js (pageC) 70 [rendered]
124+
> pageC [0] ./pageC.js
125+
[0] ./pageC.js 70 {0} [built]
126+
chunk {1} 1.chunk.js 5553 {0} {0} [rendered]
127+
> [0] ./pageA.js 1:0-3:2
128+
> aggressive-merge [0] ./pageB.js 1:0-3:2
129+
[3] ./common.js 5553 {1} [built]
130+
amd require ./common [0] ./pageA.js 1:0-3:2
131+
amd require ./common [0] ./pageB.js 1:0-3:2
132+
chunk {2} 2.chunk.js 42 {0} [rendered]
133+
> [0] ./pageC.js 1:0-3:2
134+
[1] ./a.js 21 {0} {2} [built]
135+
cjs require ./a [0] ./pageA.js 2:8-22
136+
amd require ./a [0] ./pageC.js 1:0-3:2
137+
[2] ./b.js 21 {0} {2} [built]
138+
cjs require ./b [0] ./pageB.js 2:8-22
139+
cjs require ./b [0] ./pageC.js 2:17-31
140+
141+
WARNING in 1.chunk.js from UglifyJs
142+
Dropping unused variable justToBeABigFile [./common.js:4,0]
143+
```

examples/agressive-merging/a.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a";

examples/agressive-merging/b.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.NO_TARGET_ARGS = true;
2+
require("../build-common");

examples/agressive-merging/common.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require(["./common"], function(common) {
2+
common(require("./a"));
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require(["./common"], function(common) {
2+
common(require("./b"));
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require(["./a"], function(a) {
2+
console.log(a + require("./b"));
3+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# pageA.js
2+
3+
``` javascript
4+
{{pageA.js}}
5+
```
6+
7+
# pageB.js
8+
9+
``` javascript
10+
{{pageB.js}}
11+
```
12+
13+
# pageC.js
14+
15+
``` javascript
16+
{{pageB.js}}
17+
```
18+
19+
# common.js
20+
21+
a big file...
22+
23+
# webpack.config.js
24+
25+
``` javascript
26+
{{webpack.config.js}}
27+
```
28+
29+
# Info
30+
31+
## Uncompressed
32+
33+
```
34+
{{stdout}}
35+
```
36+
37+
## Minimized (uglify-js, no zip)
38+
39+
```
40+
{{min:stdout}}
41+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var path = require("path");
2+
var AggressiveMergingPlugin = require("../../lib/optimize/AggressiveMergingPlugin");
3+
module.exports = {
4+
entry: {
5+
pageA: "./pageA",
6+
pageB: "./pageB",
7+
pageC: "./pageC"
8+
},
9+
output: {
10+
path: path.join(__dirname, "js"),
11+
filename: "[name].bundle.js",
12+
chunkFilename: "[id].chunk.js"
13+
},
14+
plugins: [
15+
new AggressiveMergingPlugin({
16+
minSizeReduce: 1.5,
17+
moveToParents: true
18+
})
19+
]
20+
}

0 commit comments

Comments
 (0)