[Webpack 2] Grouping vendor files with the Webpack Commonschunkplugin

Source: Internet
Author: User
Tags browser cache

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.