不同的babel环境配置

时间:2017-03-25 14:54:04

标签: javascript webpack babeljs webpack-2

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

webpack config I'm using

.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是什么?

0 个答案:

没有答案