[Webpack 2] Grouping vendor files with the Webpack CommonsChunkPlugin
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的更多相关文章
- webpack入门(二)what is webpack
webpack is a module bundler.webpack是一个模块打包工具,为了解决上篇一提到的各种模块加载或者转换的问题. webpack takes modules with dep ...
- Webpack+React项目入门——入门及配置Webpack
一.入门Webpack 参考文章:<入门Webpack,看这篇就够了> 耐心看完这篇非常有帮助 二.React+Webpack环境配置 参考文章:<webpack+react项目初体 ...
- webpack构建多页面react项目(webpack+typescript+react)
目录介绍 src:里面的每个文件夹就是一个页面,页面开发相关的组件.图片和样式文件就存放在对应的文件夹下. tpl:里面放置模板文件,当webpack打包时为html-webpack-plugin插件 ...
- webpack安装低于4版本(没有配置webpack.config.js)
webpack安装低于4版本(没有配置webpack.config.js) webpack 无需配置输出参数-o 低版本 1.初始化项目 npm init -y 初始化项目 2.安装webpack@ ...
- 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 ...
- 【Webpack】373- 一看就懂之 webpack 高级配置与优化
本文原载于 SegmentFault 社区专栏 前海拾贝 作者:JS_Even_JS 一.打包多页面应用 所谓打包多页面,就是同时打包出多个 html 页面,打包多页面也是使用 html-webpac ...
- Webpack学习笔记一:What is webpack
#,Loaders干嘛的,webpack can only process JavaScript natively, but loaders are used to transform other ...
- webpack需要全局安装,才能使用webpack命令
webpack全局安装,具体项目中才能使用webpack命令: npm install webpack -g
- [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 ...
随机推荐
- java 堆与栈的区别
1. 堆与栈的区别? 1-1. 数据存放位置: 数据都存放于RAM (Random Access Memory). 1-2. 存放数据的类型:stack栈中保存方法中的基本数据类型(int, do ...
- svn删除目录后提交显示Item 'XXXX' is out of date解决方法
1.在要删除的目录上执行 svn 的 Delete 2.来到要删除目录的上级目录,执行更新操作. 3.找到要删除的目录,会显示冲突状态,在这个目录上执行Resolved. 4.在这个要删除的目录上 ...
- 解读30个提高Web程序执行效率的好经验
其实微博是个好东西,关注一些技术博主之后,你不用再逛好多论坛了,因为一些很好的文章微博会告诉你,最近看到酷勤网推荐的一篇文章<30个提高Web程序执行效率的好经验>,文章写得不错,提到一些 ...
- git stash的使用
https://git-scm.com/docs/git-stash 在git svn的时候使用,提交记录的时候,有部分文件的修改不需要commit. 在向svn进行git svn dcommit的时 ...
- Learning WCF Chapter2 Data Contracts
A data contract describes how CLR types map to XSD schema definitions. Data contracts are the prefer ...
- 一起啃PRML - 1.2 Probability Theory 概率论
一起啃PRML - 1.2 Probability Theory @copyright 转载请注明出处 http://www.cnblogs.com/chxer/ A key concept in t ...
- python 以标准输出(sys.stdout)为例,看python的标准输入、标准错误输出
看了一个博客,挺不错的.http://www.cnblogs.com/turtle-fly/p/3280519.html 标准输出(sys.stdout)对应的操作就是print(打印)了,标准输入( ...
- DATE_FORMAT()(转)
mysql中DATE_FORMAT(date, format)函数可根据format字符串格式化日期或日期和时间值date,返回结果串. 也可用DATE_FORMAT( ) 来格式化DATE 或DAT ...
- show drop down menu within/from action bar
show drop down menu within/from action bar */--> pre { background-color: #2f4f4f;line-height: 1.6 ...
- kvm 对虚拟机里面插u盘
KVM虚拟机上关于宿主机的USB设备使用问题探究 KVM usb passthrough就是将宿主机的usb接口直接给虚拟机使用,usb接口上的设备也就直接可以在虚拟机上使用: 测试通过usb pas ...