Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 6, 2016
2 parents 0a4a827 + 98056a3 commit 5811c57
Show file tree
Hide file tree
Showing 12 changed files with 528 additions and 0 deletions.
403 changes: 403 additions & 0 deletions examples/common-chunk-and-vendor-chunk/README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/common-chunk-and-vendor-chunk/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global.NO_TARGET_ARGS = true;
require("../build-common");
4 changes: 4 additions & 0 deletions examples/common-chunk-and-vendor-chunk/pageA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var utility1 = require('./utility1');
var utility2 = require('./utility2');

module.exports = "pageA";
4 changes: 4 additions & 0 deletions examples/common-chunk-and-vendor-chunk/pageB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var utility2 = require('./utility2');
var utility3 = require('./utility3');

module.exports = "pageB";
4 changes: 4 additions & 0 deletions examples/common-chunk-and-vendor-chunk/pageC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var utility2 = require('./utility2');
var utility3 = require('./utility3');

module.exports = "pageC";
82 changes: 82 additions & 0 deletions examples/common-chunk-and-vendor-chunk/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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.

To better understand, here are the entry points and which utility modules they depend on:

- `pageA`
- `utility1`
- `utility2`
- `pageB`
- `utility2`
- `utility3`
- `pageC`
- `utility2`
- `utility3`

Given this configuration, webpack will produce the following bundles:

- `vendor`
- webpack runtime
- `vendor1`
- `vendor2`
- `common`
- `utility2`
- `utility3`
- `pageA`
- `pageA`
- `utility1`
- `pageB`
- `pageB`
- `pageC`
- `pageC`

With this bundle configuration, you would load your third party libraries, then your common application code, then your page-specific application code.

# webpack.config.js

``` javascript
{{webpack.config.js}}
```

# js/vendor.js

``` javascript
{{js/vendor.js}}
```

# js/common.js

``` javascript
{{js/common.js}}
```

# js/pageA.js

``` javascript
{{js/pageA.js}}
```

# js/pageB.js

``` javascript
{{js/pageB.js}}
```

# js/pageC.js

``` javascript
{{js/pageC.js}}
```

# Info

## Uncompressed

```
{{stdout}}
```

## Minimized (uglify-js, no zip)

```
{{min:stdout}}
```
1 change: 1 addition & 0 deletions examples/common-chunk-and-vendor-chunk/utility1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "utility1";
1 change: 1 addition & 0 deletions examples/common-chunk-and-vendor-chunk/utility2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "utility2";
1 change: 1 addition & 0 deletions examples/common-chunk-and-vendor-chunk/utility3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "utility3";
1 change: 1 addition & 0 deletions examples/common-chunk-and-vendor-chunk/vendor1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "vendor1";
1 change: 1 addition & 0 deletions examples/common-chunk-and-vendor-chunk/vendor2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "vendor2";
24 changes: 24 additions & 0 deletions examples/common-chunk-and-vendor-chunk/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var path = require("path");
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");

module.exports = {
entry: {
vendor: ["./vendor1", "./vendor2"],
pageA: "./pageA",
pageB: "./pageB",
pageC: "./pageC"
// older versions of webpack may require an empty entry point declaration here
// common: []
},
output: {
path: path.join(__dirname, "js"),
filename: "[name].js"
},
plugins: [
new CommonsChunkPlugin({
// The order of this array matters
names: ["common", "vendor"],
minChunks: 2
})
]
};

0 comments on commit 5811c57

Please sign in to comment.