Skip to content

Commit 8bbad20

Browse files
committed
Common and vendor chunk example
1 parent dc7a19d commit 8bbad20

12 files changed

Lines changed: 528 additions & 0 deletions

File tree

examples/common-chunk-and-vendor-chunk/README.md

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.
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");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var utility1 = require('./utility1');
2+
var utility2 = require('./utility2');
3+
4+
module.exports = "pageA";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var utility2 = require('./utility2');
2+
var utility3 = require('./utility3');
3+
4+
module.exports = "pageB";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var utility2 = require('./utility2');
2+
var utility3 = require('./utility3');
3+
4+
module.exports = "pageC";
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
This example shows how to create an explicit vendor chunk as well as a common chunk for code shared among entry points. In this example, we have 3 entry points: `pageA`, `pageB`, and `pageC`. Those entry points share some of the same utility modules, but not others. This configuration will pull out any modules common to at least 2 bundles and place it it the `common` bundle instead, all while keeping the specified vendor libraries in their own bundle by themselves.
2+
3+
To better understand, here are the entry points and which utility modules they depend on:
4+
5+
- `pageA`
6+
- `utility1`
7+
- `utility2`
8+
- `pageB`
9+
- `utility2`
10+
- `utility3`
11+
- `pageC`
12+
- `utility2`
13+
- `utility3`
14+
15+
Given this configuration, webpack will produce the following bundles:
16+
17+
- `vendor`
18+
- webpack runtime
19+
- `vendor1`
20+
- `vendor2`
21+
- `common`
22+
- `utility2`
23+
- `utility3`
24+
- `pageA`
25+
- `pageA`
26+
- `utility1`
27+
- `pageB`
28+
- `pageB`
29+
- `pageC`
30+
- `pageC`
31+
32+
With this bundle configuration, you would load your third party libraries, then your common application code, then your page-specific application code.
33+
34+
# webpack.config.js
35+
36+
``` javascript
37+
{{webpack.config.js}}
38+
```
39+
40+
# js/vendor.js
41+
42+
``` javascript
43+
{{js/vendor.js}}
44+
```
45+
46+
# js/common.js
47+
48+
``` javascript
49+
{{js/common.js}}
50+
```
51+
52+
# js/pageA.js
53+
54+
``` javascript
55+
{{js/pageA.js}}
56+
```
57+
58+
# js/pageB.js
59+
60+
``` javascript
61+
{{js/pageB.js}}
62+
```
63+
64+
# js/pageC.js
65+
66+
``` javascript
67+
{{js/pageC.js}}
68+
```
69+
70+
# Info
71+
72+
## Uncompressed
73+
74+
```
75+
{{stdout}}
76+
```
77+
78+
## Minimized (uglify-js, no zip)
79+
80+
```
81+
{{min:stdout}}
82+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "utility1";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "utility2";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "utility3";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "vendor1";

0 commit comments

Comments
 (0)