环境版本
NodeJs:v14.18.1
@vue/cli 4.5.15
babel 6.26.0 (babel-core 6.26.3)
项目是若依
参考文档
【vue-router踩坑】使用vite打包项目vue-router懒加载无效】
操作步骤
-
安装
syntax-dynamic-import插件npm install --save-dev @babel/plugin-syntax-dynamic-import -
修改项目
babel.config.js文件原来用的插件是
dynamic-import-node,改成syntax-dynamic-importmodule.exports = { presets: [ // https://github.com/vuejs/vue-cli/tree/master/packages/@vue/babel-preset-app '@vue/cli-plugin-babel/preset' ], 'env': { 'development': { // babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require(). // This plugin can significantly increase the speed of hot updates, when you have a large number of pages. // 'plugins': ['dynamic-import-node'] 'plugins': ["syntax-dynamic-import"] } } } -
打包
本文介绍了解决Vue项目中使用vite打包时遇到的vue-router懒加载失效的问题。通过安装并配置@babel/plugin-syntax-dynamic-import插件,实现了对动态导入语法的支持,从而解决了懒加载功能无法正常工作的情况。
3388

被折叠的 条评论
为什么被折叠?



