[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 ...
随机推荐
- Ubuntu下Memcache的安装与基本使用
安装Memcache Memcache分为两部分,Memcache服务端和客户端.Memcache服务端是作为服务来运行的,所有数据缓存的建立,存储,删除实际上都是在这里完成的.客户端,在这里我们指的 ...
- IAR中 C语言位定义
__IO_REG8_BIT( SYS, 0xFFFFF802, __READ_WRITE ) #define __IO_REG8_BIT(NAME, ADDRESS, A ...
- Spring 自动装配
1.自动装配有 bytype 和byName两种模式. 2.可以使用autowire属性指定自动装配的方式,byName根据bean的名称和当前bean的setter风格属性进行自动装配:byType ...
- 使用solrj进行DIH操作
背景说明:在一个项目中需要将Mongodb中的数据导入到solr中完成搜索.在solr中Mysql数据库有对应的DIH包,可以通过配置sql语句完成数据的导入.Mongodb下也有开源的工具用来实现数 ...
- 【Xamarin挖墙脚系列:卸载不彻底的解决】
原文:[Xamarin挖墙脚系列:卸载不彻底的解决] 卸载后,再次安装,总是授权还是原来的.请手工删除下文件: 卸载程序后 必须手工删除C:\ProgramData\Mono for Android\ ...
- Android应用架构
Android开发生态圈的节奏非常之快.每周都会有新的工具诞生,类库的更新,博客的发表以及技术探讨.如果你外出度假一个月,当你回来的时候可能已经发布了新版本的Support Library或者Play ...
- Android Animation
Android中常用两种动画模式,tween animation和frame animation,即补间动画和帧动画,但在android3.0中又引入了一个新的动画系统:property animat ...
- 主线程中有多个handler的情况
工作中遇到了这么一种情况,有两个视图,都需要开启异步任务从服务器获取数据,每个view中创建一个Handler,注册到异步任务中去,当异步任务从服务器获取数据出错,或者出现io异常或者http协议异常 ...
- 【HDOJ】2133 What day is it
需要注意数据有效性. #include <stdio.h> #define isLeapYear(y) (y%4==0&&y%100!=0)||(y%400==0) ][] ...
- wpa_supplicant对wep,wpa,wpa2的psk和隐藏ap的scan_ssid扫描配置
# 请不要修改下面这一行内容,否则将不能正常工作ctrl_interface=/var/run/wpa_supplicant # 确保只有root用户能读取WPA的配置ctrl_interface_g ...