Often, you have dependencies which you rarely change. In these cases, you can leverage the CommonsChunkPlugin to automatically put these modules in a separate bundled file so they can be cached and loaded separately from the rest of your code (leveraging the browser cache much more effectively).

The libaraies like 'lodash', 'jquery' are required alomost all the projects and once download, rarly change any more. So it would be a good idea to spreate those common libaries into a common vendor file.

  entry: {
app: './js/app.js',
vendor: ['lodash', 'jquery'],
},

So rename the entry, add 'app' and 'vendor' entries.

So the output file canbe named like 'bundle.app.js' and 'bundle.vendor.js':

  output: {
filename: 'bundle.[name].js',
path: resolve(__dirname, 'dist'),
pathinfo: true,
},

We will use webpack build in CommonsChunkPlugin:

  plugins: [
isTest ? undefined : new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
}),
].filter(p => !!p),

Now we can include those two bundle files into index.html:

    <script src="/bundle.vendor.js"></script>
<script src="/bundle.app.js"></script>

[Webpack 2] Grouping vendor files with the Webpack CommonsChunkPlugin的更多相关文章

  1. webpack入门(二)what is webpack

    webpack is a module bundler.webpack是一个模块打包工具,为了解决上篇一提到的各种模块加载或者转换的问题. webpack takes modules with dep ...

  2. Webpack+React项目入门——入门及配置Webpack

    一.入门Webpack 参考文章:<入门Webpack,看这篇就够了> 耐心看完这篇非常有帮助 二.React+Webpack环境配置 参考文章:<webpack+react项目初体 ...

  3. webpack构建多页面react项目(webpack+typescript+react)

    目录介绍 src:里面的每个文件夹就是一个页面,页面开发相关的组件.图片和样式文件就存放在对应的文件夹下. tpl:里面放置模板文件,当webpack打包时为html-webpack-plugin插件 ...

  4. webpack安装低于4版本(没有配置webpack.config.js)

    webpack安装低于4版本(没有配置webpack.config.js) webpack 无需配置输出参数-o 低版本  1.初始化项目 npm init -y 初始化项目 2.安装webpack@ ...

  5. webpack笔记_(2)_Refusing to install webpack as a dependency of itself

    安装webpack时,出现以下问题: Refusing to install webpack as a dependency of itself npm ERR! Windows_NT npm ERR ...

  6. 【Webpack】373- 一看就懂之 webpack 高级配置与优化

    本文原载于 SegmentFault 社区专栏 前海拾贝 作者:JS_Even_JS 一.打包多页面应用 所谓打包多页面,就是同时打包出多个 html 页面,打包多页面也是使用 html-webpac ...

  7. Webpack学习笔记一:What is webpack

      #,Loaders干嘛的,webpack can only process JavaScript natively, but loaders are used to transform other ...

  8. webpack需要全局安装,才能使用webpack命令

    webpack全局安装,具体项目中才能使用webpack命令: npm install webpack -g

  9. [Webpack 2] Expose modules to dependencies with Webpack

    When you have a dependency that has dependencies on global variables (like jQuery or lodash) or assu ...

随机推荐

  1. ms-on-input

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. AD RMS Bulk Protection Tool 批量加密解密office文档

    1.Active Directory Rights Management Services Bulk Protection Tool  http://www.microsoft.com/zh-cn/d ...

  3. 我是如何实用:before :after

    本文地址http://www.cnblogs.com/Bond/p/3972854.html 最近一直做移动端,没和IE6打交道了,瞬间感觉世界变美好了.移动端虽然还是各种坑,但是比起修复IE6那还是 ...

  4. Mozilla对HTML5规范支持列表

    翻译自Mozilla Developer Network 在2009年10月28日,HTML 5规范草稿在网络超文本应用技术工作组(WHATWG)中基本出于最后定稿阶段,这意味着HTML 5标准基本定 ...

  5. [wikioi]关押罪犯

    错误半天还是因为并查集写错了.写错的地方是合并X和Y的时候,应该把FX挂到FY上去,而不是把X挂到Y上或FY上去,因为FX和FY下面有一树别的节点. http://www.nocow.cn/index ...

  6. OA学习笔记-007-Dao层设计

    一. User, UserDao save(User user), update(), delete(), find(), ...Role, RoleDao save(Role role), upda ...

  7. async await 异步编程杂记

    1. async 仅仅是用了标记 方法中有异步调用(就是有await...) 2  await  用来把「当前线程」中的代码“分成片”,通过一定条件和事件回调的形式  “依次执行”. 3. await ...

  8. eclipse导入已有源码

    http://blog.csdn.net/scruffybear/article/details/1917301 如有转载,请注明出处,并保持文章的完整性,谢谢! 最近工作之余在研究国外经典书籍< ...

  9. Rewriting History with Git Rebase

    http://code.tutsplus.com/tutorials/rewriting-history-with-git-rebase--cms-23191 1. Rebasing for a Li ...

  10. USACO3.32Shopping Offers(DP)

    五维DP,听着挺多的,貌似就是挺裸的dp, 最近貌似做简单的DP挺顺手..1A dp[i][j][e][o][g] = min(dp[i][j][e][o][g],dp[i-i1][j-i2][e-i ...