使Babel排除测试文件 [英] Make babel exclude test files
问题描述
在构建步骤中,我正在使用babel将代码转换为es5(从src
到dist
).如何排除以.test.js
结尾的文件?
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
package.json
"scripts": {
"build": "babel src --out-dir dist",
.babelrc
{
"presets": [ "es2015" ],
"ignore": "\\.test\\.js"
}
推荐答案
基于文档,您应该能够编写.babelrc
Based on the documentation, you should be able to write .babelrc
{
"ignore": [
"**/*.test.js"
]
}
但是,我能够验证这似乎不起作用.我在6.5.1版(babel-core 6.5.2版)中进行了尝试.
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).
同时,以下工作有效:
babel src --out-dir build --ignore '**/*.test.js'
这与在.babelrc
文件中编写的模式相同.如果您从npm安装任何glob库,您会发现此glob模式将起作用(这就是我想出的方式...我目前不使用babel).
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).
这篇关于使Babel排除测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!