node.js 使 babel 排除测试文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35415301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make babel exclude test files
提问by Manuel
On my build step I'm using babel to transpile the code to es5 (from srcto dist). How do I make it exclude files ending in .test.js?
在我的构建步骤中,我使用 babel 将代码转换为 es5(从src到dist)。我如何使它排除以 结尾的文件.test.js?
package.json
包.json
"scripts": {
"build": "babel src --out-dir dist",
.babelrc
.babelrc
{
"presets": [ "es2015" ],
"ignore": "\.test\.js"
}
回答by Wil Moore III
Based on the documentation, you should be able to write .babelrc
根据文档,您应该能够编写 .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).
但是,我能够验证这似乎不起作用。我用 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 .babelrcfile. 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).
这与.babelrc文件中写入的 glob 模式相同。如果你从 npm 安装任何 glob 库,你会发现这个 glob 模式可以工作(这就是我想出它的方式......我目前不使用 babel)。
回答by Pubudu Dodangoda
As of today, the following works in .babelrc (babel-core: v6.26.3)
截至今天,以下工作在 .babelrc (babel-core: v6.26.3)
"ignore": [
"**/__tests__", // ignore the whole test directory
"**/*.test.js" // ignore test files only
]

