使用Vue開發的項目在用Webpack打包以後vender和app這兩個js文件可能很大,並且有不少的map文件,其體積也不小,那麼如何優化打包後體積呢?javascript
在webpack.base.conf.js文件中添加打包排除項:css
externals: { 'vue': 'Vue', 'echarts': 'echarts', 'axios': 'axios', 'vuex': 'Vuex' },
而後去掉main.js中的導入,在index.html添加BootCDN的連接:html
<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>
在config/index.js中設置:vue
cssSourceMap: false, productionSourceMap: false, productionGzip: true,
component: (resolve) => require(['../components/Index.vue'], resolve)