Make babel exclude test files

爱⌒轻易说出口 提交于 2020-05-25 03:21:57

问题


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"
}

回答1:


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).




回答2:


As of today, the following works in .babelrc (babel-core: v6.26.3)

"ignore": [
  "**/__tests__", // ignore the whole test directory
  "**/*.test.js" // ignore test files only
]


来源:https://stackoverflow.com/questions/35415301/make-babel-exclude-test-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!