如何告诉Babel CLI忽略其中带有“ __”的任何路径?

时间:2019-02-27 22:02:54

标签: node.js babel glob babel-cli

"@babel/cli": "^7.2.3",

似乎真的很简单。

https://babeljs.io/docs/en/babel-cli#ignore-files

 babel src --out-dir lib --ignore "src/**/*.spec.js","src/**/*.test.js"

所以我将其设置为:

babel src --out-dir cjs --ignore "**/_*" --copy-file --watch

全球参考:https://github.com/isaacs/node-glob

但是我在输出中看到了这一点:

add:cjs/__mocks__/@xyz/common-fn.js
add:cjs/middleware/__mocks__/uuid.js 

好的,我试试这个:

babel src --out-dir cjs --ignore "**/_+","_+" --copy-file --watch

这些:

babel src --out-dir cjs --ignore "**/_*/*.*\ --copy-file --watch 
babel src --out-dir cjs --ignore "**/__mocks__/*.*",  --copy-file --watch 
babel src --out-dir cjs --ignore "[src|middleware]/**/__mocks__/*.*" --copy-file --watch"
babel src --out-dir cjs --ignore "**/_+/**/*.*" --copy-file --watch

每次结果相同。 看起来最后一个应该确实有效:忽略目录中包含零个或多个目录的路径,然后是名称中至少包含一个_的目录,然后是零个或多个目录,然后是匹配任何模式的文件。我读对了吗?

然后我尝试非常具体:

babel src --out-dir cjs --ignore "nes/middleware/__mocks__/*.js", --copy-file --watch

然后我得到:

add:nes/middleware/__mocks__/localize.js

我不知道这是Babel中的错误还是我误解了glob模式。

1 个答案:

答案 0 :(得分:0)

关于whether Babel fully supports Glob patterns at the CLI level.

似乎有一些争论

我设法使其使用这种忽略模式:

--ignore "src/**/__mocks__/**/*.js" --ignore "src/**/*.test.js"

此模式**/__*/**在Glob中有效,但在Babel中无效。

相关问题