File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,40 @@ module.exports = function(env) {
178
178
};
179
179
```
180
180
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
+ ```
182
216
183
217
T> Note that long-term bundle caching is achieved with content-based hashing policy ` chunkhash ` . Learn more about [ caching] ( /guides/caching/ ) .
You can’t perform that action at this time.
0 commit comments