1

I am using babel and have a .babelrc file for its configuration:

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

However, when I'm developing locally, having this .babelrc file disallows me from running Babel's CLI babel-node in the testing folder (see: babel-node no longer working in different directory )

That said, when I push to Heroku, I need this configuration because I need to make sure the testing folder isn't compiled.

How can I conditionally set a .babelrc file that doesn't involve me having to remember to switch it back to the production version everytime I want to push to Heroku?

Community
  • 1
  • 1
Anthony
  • 13,434
  • 14
  • 60
  • 80

1 Answers1

1

You can set conditional things using the env option in your .babelrc

from their docs:

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

Then, in your package.json

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

it checks BABEL_ENV, then NODE_ENV

psimyn
  • 406
  • 5
  • 12