Make babel exclude test files

Manuel picture Manuel · Feb 15, 2016 · Viewed 30.9k times · Source

On my build step I'm using babel to transpile the code to es5 (from src to dist). How do I make it exclude files ending in .test.js?

package.json

"scripts": {
  "build": "babel src --out-dir dist",

.babelrc

{
  "presets": [ "es2015" ],
  "ignore": "\\.test\\.js"
}

Answer

Wil Moore III picture Wil Moore III · Feb 15, 2016

Based on the documentation, you should be able to write .babelrc

{
  "ignore": [
    "**/*.test.js"
  ]
}

However, I was able to verify that this does not seem to work. I tried it with version 6.5.1 (babel-core 6.5.2).

At the same time, the following does work:

babel src --out-dir build --ignore '**/*.test.js'

That is the same glob pattern as written in the .babelrc file. If you install any glob library from npm you'll find that this glob pattern would work (that is how I came up with it...I do not currently use babel).