vue打包后vendor.js文件过大解决方案

栏目: 编程语言 · 发布时间: 5年前

内容简介:index.html中cdn的方式引入vue、vuex、axios、element-ui、vue-router等包,如下图:在所有使用vue的地方注释掉引入的vue等包,但是Vue.use(axios)、Vue.use(VueRoter)、Vue.use(vuex)等依然要使用,除了Vue.use(ElementUI), 如果加上这句话,还是会打包element-ui到vendor.js文件中

第一步、cdn引入各种包

index.html中cdn的方式引入vue、vuex、axios、element-ui、vue-router等包,如下图:

vue打包后vendor.js文件过大解决方案

第二步、在使用vue等包的地方,注释掉import引入

在所有使用vue的地方注释掉引入的vue等包,但是Vue.use(axios)、Vue.use(VueRoter)、Vue.use(vuex)等依然要使用,除了Vue.use(ElementUI), 如果加上这句话,还是会打包element-ui到vendor.js文件中

在main.js

vue打包后vendor.js文件过大解决方案

在store文件加中的index.js

vue打包后vendor.js文件过大解决方案

在api/request.js文件中

vue打包后vendor.js文件过大解决方案

在router/index.js文件中

vue打包后vendor.js文件过大解决方案

第三步、打包忽视掉vue等包

在webpack.base.conf.js

vue打包后vendor.js文件过大解决方案

第四步、如果打包后的文件还是比较大,就采用路由懒加载的方式加载路由

vue打包后vendor.js文件过大解决方案

最终打包结果

vendor.js的大小由原来的988k, 降到235k

vue打包后vendor.js文件过大解决方案


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Spring in Action

Spring in Action

Craig Walls / Manning Publications / 2011-6-29 / USD 49.99

Spring in Action, Third Edition has been completely revised to reflect the latest features, tools, practices Spring offers to java developers. It begins by introducing the core concepts of Spring and......一起来看看 《Spring in Action》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具