Vue项目使用Webpack打包体积优化
使用Vue开发的项目在用Webpack打包之后vender和app这两个js文件可能很大,而且有很多的map文件,其体积也不小,那么如何优化打包后体积呢?
引入CDN
在webpack.base.conf.js文件中添加打包排除项:
externals: { ‘vue‘: ‘Vue‘, ‘echarts‘: ‘echarts‘, ‘axios‘: ‘axios‘, ‘vuex‘: ‘Vuex‘ },
然后去掉main.js中的导入,在index.html添加BootCDN的链接:
<link href="https://cdn.bootcss.com/element-ui/2.12.0/theme-chalk/index.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script> <script src="https://cdn.bootcss.com/vuex/3.1.1/vuex.min.js"></script> <script src="https://cdn.bootcss.com/echarts/4.4.0-rc.1/echarts.min.js"></script> <script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>
关闭SourceMap生成
在config/index.js中设置:
cssSourceMap: false, productionSourceMap: false, productionGzip: true,
路由懒加载
component: (resolve) => require([‘../components/Index.vue‘], resolve)
相关推荐
gloria0 2020-10-26
gloria0 2020-08-09
hline 2020-07-29
不知道该写啥QAQ 2020-07-18
不知道该写啥QAQ 2020-11-12
webfullStack 2020-11-09
Yvettre 2020-09-15
想做大牛的蜗牛 2020-10-30
gaojie0 2020-09-11
SelinaChan 2020-08-14
不知道该写啥QAQ 2020-08-09
不知道该写啥QAQ 2020-08-02
SelinaChan 2020-07-28
wangdianyong 2020-07-23
webpackvuees 2020-07-23
yqoxygen 2020-07-20
waterv 2020-07-18
81463166 2020-07-17