Skip to content

Commit 0eaf572

Browse files
authored
Merge pull request #1045 from mkarajohn/patch-2
Extended last example in code-splitting-libraries.md
2 parents 0f80c77 + d7c3eb9 commit 0eaf572

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

content/guides/code-splitting-libraries.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,40 @@ module.exports = function(env) {
178178
};
179179
```
180180

181-
With the above webpack config, we see three bundles being generated. `vendor`, `main` and `manifest` bundles.
181+
With the above webpack config, we see three bundles being generated. `vendor`, `main` and `manifest` bundles.
182+
183+
Using what we have learned so far, we could also achieve the same result with an implicit common vendor chunk.
184+
185+
__webpack.config.js__
186+
187+
```javascript
188+
var webpack = require('webpack');
189+
var path = require('path');
190+
191+
module.exports = function() {
192+
return {
193+
entry: {
194+
main: './index.js' //Notice that we do not have an explicit vendor entry here
195+
},
196+
output: {
197+
filename: '[name].[chunkhash].js',
198+
path: path.resolve(__dirname, 'dist')
199+
},
200+
plugins: [
201+
new webpack.optimize.CommonsChunkPlugin({
202+
name: 'vendor',
203+
minChunks: function (module) {
204+
// this assumes your vendor imports exist in the node_modules directory
205+
return module.context && module.context.indexOf('node_modules') !== -1;
206+
}
207+
}),
208+
//CommonChunksPlugin will now extract all the common modules from vendor and main bundles
209+
new webpack.optimize.CommonsChunkPlugin({
210+
name: 'manifest' //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
211+
})
212+
]
213+
};
214+
}
215+
```
182216

183217
T> Note that long-term bundle caching is achieved with content-based hashing policy `chunkhash`. Learn more about [caching](/guides/caching/).

0 commit comments

Comments
 (0)