vue 路由懒加载

添加babel插件

packjson.json

"babel-plugin-syntax-dynamic-import": "6.18.0",

.babelrc

    "plugins": [
        "syntax-dynamic-import"
    ],

webpack 配置

webpack.base.conf.js

output: {
        chunkFilename: "chunk[id].js?[chunkhash]"
    },

router

index.js

const home = () => import("@/pages/public/home");

{
    path: "home",
    component: home
 },
原文地址:https://www.cnblogs.com/chenzeyongjsj/p/9908841.html