Often, you have dependencies which your rarely change. In these cases, you can leverage the Commonschunkplugin-automatically put these modules in a separate bundled file so T Hey can cached and loaded separately from the rest of your code (leveraging the browser cache much more effectively).
The libaraies like ' Lodash ', ' jquery ' is required alomost all the projects and once download, and rarly change any more. So it would is a good idea to spreate those common libaries into a common vendor file.
entry: { './js/app.js', vendor: ['lodash 'jquery'], },
So rename the entry, add ' app ' and ' Vendor ' entries.
The output file canbe named like ' Bundle.app.js ' and ' bundle.vendor.js ':
output: { 'bundle.[ Name].js', 'dist'), true , },
We'll use the Webpack build in Commonschunkplugin:
plugins: [ new webpack.optimize.CommonsChunkPlugin ({ ' Vendor', }), = =!! P),
Now we can include those the bundle files into index.html:
<src= "/bundle.vendor.js"></script> < src= "/bundle.app.js"></script>
[Webpack 2] Grouping vendor files with the Webpack Commonschunkplugin