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

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

内容简介: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文件过大解决方案


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

查看所有标签

猜你喜欢:

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

Machine Learning

Machine Learning

Kevin Murphy / The MIT Press / 2012-9-18 / USD 90.00

Today's Web-enabled deluge of electronic data calls for automated methods of data analysis. Machine learning provides these, developing methods that can automatically detect patterns in data and then ......一起来看看 《Machine Learning》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试