照着官方文档
1.下载babel-plugin-component依赖项
npm install babel-plugin-component -D
2.添加/修改.babelrc文件
{
"presets": [["es2015", { "modules": false }]],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
然后就报错 Error: Cannot find module 'babel-preset-es2015
既然缺少这个依赖,那么
npm i babel-preset-es2015 -S
又报错了 Error: plugin/preset files are not allowed to export objects
疯狂百度,找到了解决方案:
1.安装@babel/preset-env;项目目录下,运行命令行
npm i @babel/preset-env --save-dev
2.修改.babelrc文件,把es2015改成@babel/preset-env
{
"presets": [["@babel/preset-env", { "modules": false }]],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
3.也可以在babel.config.js中的修改
module.exports = {
"presets": [["@babel/preset-env", { "modules": false }]],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
网友评论