使用ElementUI组件库,按需引入ElementUI,按照官方文档的代码配置会遇到的报错问题!!
错误:Cannot find module 'babel-plugin-component'
先安装babel-plugin-component:
npm install babel-plugin-component -D
vue/cli 没有.babelrc文件,而是有babel.config.js文件,按需引入时需要到babel.config.js文件里去配置
module.exports = { presets: [ '@vue/cli-plugin-babel/preset', ], plugins: [ [ "component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" } ] ] };