1.安装babel-plugin-syntax-dynamic-import(用以解析识别import()动态导入语法—并非转换,而是解析识别)
npm install babel-plugin-syntax-dynamic-import
2.在babel.config.js中配置文件中声明该插件
{
"plugins": ["syntax-dynamic-import"]
}
或者
3.在index。js中改为
const Foo = () => import(/* webpackChunkName: "group-foo" */ './Foo.vue')
const Bar = () => import(/* webpackChunkName: "group-foo" */ './Bar.vue')
const Baz = () => import(/* webpackChunkName: "group-foo" */ './Baz.vue')
实例: