vue實現按需加載(懶加載)

1.router文件中使用webpack

export default new Router({
  routes: [{
      path: '/',
      name: 'Post',
      component: () => import ('@/components/Post')
    },
    {
      path: '/After',
      name: 'After',
      component: () => import ('@/components/After')
    },
    {
      path: '/Post',
      name: 'Post',
      component: () => import ('@/components/Post')
    }
  ]
})

 

在webpack.base.conf.js文件中配置chunkFileName  web

output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    chunkFilename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
相關文章
相關標籤/搜索