关于vue-cli脚手架打包后vendor文件过大

大家会遇到打包后文件很大,导致页面初始化加载的速度很慢。会出现白屏的现象。这一般是你打包的vendor太大的缘故。如果你打包后看到你的vendor文件有700kb以上。你就要考虑怎么处理。
处理这种文件的
1、把不常改变的库放到index.html中,通过cdn引入,比如下面这样:

 <script src="https://unpkg.com/vue@2.5.2/dist/vue.js"></script>
 <script src="https://unpkg.com/vue-router@3.0.1/dist/vue-router.js"></script>
 <script src="https://unpkg.com/mint-ui@2.2.13/lib/index.js"></script>
 <script src="https://unpkg.com/element-ui@2.3.9/lib/index.js"></script>
  <script src="https://unpkg.com/axios@0.18.0/dist/axios.min.js"></script>

然后找到build/webpack.base.conf.js文件,在 module.exports = { } 中添加以下代码

  externals:{
    'vue':'Vue',
    'element-ui':'ELEMENT',
    'mint-ui':'MINT',
    'axios':'axios',
    'vue-router':'VueRouter',
  },  

2、通过路由的懒加载

export default new VueRouter({//这个为什么用VueRouter  是通过script标签引入的
 mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/master/closestore/today'
   },

    {
      path: '/master/closestore/today',
      name: 'CloseingCount',
          component: resolve => require(['@/components/ClosingCount'], resolve)
    },
    ]});
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值