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. 8月1日起,这些新政将影响移动互联网产业-b

    今天,国家互联网信息办公室发布<移动互联网应用程序信息服务管理规定>.这项规定将从8月1日起生效,其中侧重对两类玩家提出了监管意见,他们分别是: 移动互联网应用程序提供者,即提供信息服务的 ...

  2. UML 类图的关系

    1.  关联关系 1.1 单向关联 . public class ClassA { private ClassB bVar; } public class ClassB { //... } 1.2  ...

  3. hdu 4720

    最小覆盖圆的模板: #include<stdio.h> #include<string.h> #include<math.h> struct Point { dou ...

  4. 关于entity framework

    http://www.cnblogs.com/lsxqw2004/archive/2009/05/31/1495240.html http://www.open-open.com/lib/view/o ...

  5. eclipse安装CDT插件遇到的问题

    转自eclipse安装CDT插件遇到的问题 已经安装了集成java版本的eclipse,eclipse-java-indigo-SR1-win32.zip,在添加CDT插件时,遇到了问题. cdt-m ...

  6. ANDROID_MARS学习笔记_S04_004_用HTTPCLENT发带参数的get和post请求

    一.代码 1.xml(1)activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...

  7. ruby面向对象class

    ruby对象是严格封装的:只能通过定义的方法访问其内部状态.方法使用的成员变量在对象外部不能直接访问,不过可以通过getter.setter等访问器方法(accessor),使他们看起来好像是直接访问 ...

  8. git撤销提交到remote的commit

    Reseting remote to a certain commit Assuming that your branch is called master both here and remotel ...

  9. bzoj1799

    这是一道比较难的数位dp 因为逐位统计好像无法处理数位和整除原数的 但是有了刚才的bzoj1072的经验,我们能做的是逐位处理被一个数d整除的方案 不难想到先穷举数位和now,now最大也就162,可 ...

  10. C#数据库连接字符串

    转自:http://blog.csdn.net/xiaokexinger/article/details/1541441 在MSDN中,.net的数据库连接字符串都有详细的说明,我这里以代码范例的方式 ...