如何有条件地设置.rc文件

时间:2015-11-22 22:56:33

标签: shell heroku babeljs rc

我正在使用babel并为其配置提供了.babelrc文件:

{
  "stage": 0,
  "ignore": [
    "node_modules",
    "bower_components",
    "testing",
    "test"
  ]
}

但是,当我在本地开发时,让这个.babelrc文件禁止我在babel-node文件夹中运行Babel的CLI testing(请参阅:{{ 3}})

那就是说,当我推送到Heroku时,我需要这个配置,因为我需要确保测试文件夹没有被编译。

如何有条件地设置一个.babelrc文件,并不会让我每次想要推送到Heroku时都要记得将其切换回生产版本?

1 个答案:

答案 0 :(得分:1)

您可以使用env

中的.babelrc选项设置条件事项

来自their docs

{
  "stage": 0,
  "env": {
    "development": {
      "ignore": [
        "node_modules",
        "bower_components",
        "testing",
        "test"
      ]
    }
  }
}

然后,在package.json

"scripts": {
  "start": "NODE_ENV=production node index.js",
  "dev": "NODE_ENV=development node index.js"
}

它检查BABEL_ENV,然后检查NODE_ENV

相关问题