什么问题会导致vue路由懒加载之后页面没有引入打包后的路由文件?

vue路由懒加载之后页面没有引入打包后的路由文件,导致页面空白

webpack

output: {
    path: path.resolve(__dirname, './dist'),
    filename: 'js/[name].bundle.js',
    chunkFilename: 'js/[name].[hash:8].js',
},

router.js

Vue.use(VueRouter)
const routerLazyLoad = filename => () => () => import(
    /* webpackChunkName: "[request]" */`./components/${filename}.vue`
)
module.exports = new VueRouter({
    routes: [
        {
            path: '/', redirect: '/home'
        },
        {
            path: '/home', component: routerLazyLoad('Home')
        },
        {
            path: '/login', component: routerLazyLoad('Login')
        },
        {
            path: '/seniority', component: routerLazyLoad('Seniority')
        },
        {
            path: '/seniorityAll', component: routerLazyLoad('SeniorityAll')
        }
    ]
}) 
   

打包后的路由文件
而且还发现多打包了两个子组件,tabbar和toast,难道是只要在上述被懒加载的组件中引用过就会被打包吗?

今天我把output中的chunkFilename注释掉了,发现依然会打包路由文件... 很懵逼

阅读 3.6k
2 个回答

解决了...
原来是我的箭头函数写的有问题... 对箭头函数理解的还是太浅了...
退一步就解决了..

const routerLazyLoad = filename => {
    return () => import(
        /* webpackChunkName: "[request]" */`./components/${filename}.vue`
    )
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题