This answer似乎过时了。
当前依赖
babel: ^6.5.2
babel-core: ^6.10.4
babel-loader: ^7.0.0-beta.1
webpack: ^2.3.2
webpack-dev-server: ^2.4.2
npm 脚本
// points to specific dev configuration
"serve": NODE_ENV=development webpack-dev-server --hot --config ./webpack/development.js
.babelrc
{
"env": {
"development": {
"presets": [
"es2015",
"stage-0",
"react",
"react-hmre"
],
"plugins": [
"babel-plugin-root-import",
"react-html-attrs",
"transform-es2015-destructuring",
"transform-object-rest-spread",
"syntax-object-rest-spread"
]
},
"production": ...
"test": ...
}
}
Babel docs说要使用上面的 .babelrc env
配置,他们还提到要使用这个特定的 presets
config -- 然而,babel-loader 在上述配置中抛出了这个错误:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
让不同环境工作的正确 .babelrc
是什么?
最佳答案
presets
键的正确语法是每个错误消息的列表列表。如果您将代码更正为以下内容,它应该可以工作:
{
"env": {
"development": {
"presets": [
"es2015",
"stage-0",
"react",
"react-hmre"
],
"plugins": [
"babel-plugin-root-import",
"react-html-attrs",
"transform-es2015-destructuring",
"transform-object-rest-spread",
"syntax-object-rest-spread"
]
},
"production": ...
"test": ...
}
}
关于javascript - 不同的babel环境配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43017855/