node.js Glob 匹配,排除所有 JS 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23557305/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:18:01  来源:igfitidea点击:

Glob matching, exclude all JS files

node.jspattern-matchingglobgulp

提问by AlexZ

I'm a new user to gulp.js. I'd like to move all of my non-javascript files to a build directory. What I've got right now is this:

我是 gulp.js 的新用户。我想将所有非 JavaScript 文件移动到构建目录。我现在得到的是:

//Test copy
gulp.task('test-copy', function() {
    gulp.src(['myProject/src/**/*.!(js|map|src)'])
        .pipe(gulp.dest('myProject/build'));
});


//Results for various files
myProject/css/style.css //Copied - GOOD
myProject/html/index.html //Copied - GOOD
myProject/js/foo.js //Not Copied - GOOD
myProject/js/bar.min.js //Copied - BAD!
myProject/js/jquery-2.0.3.min.js //Copied - BAD!
myProject/js/jquery-2.0.3.min.map //Copied - BAD!

As you can see, it only matches after the first dot in the file path string, not the last one, as I'd like. How can I modify the glob search string to behave as I'd like?

如您所见,它只匹配文件路径字符串中的第一个点之后,而不是最后一个,正如我所希望的。如何修改 glob 搜索字符串以按我的意愿行事?

回答by TurboHz

Try this glob pattern:

试试这个 glob 模式:

myProject/src/**/!(*.js|*.map|*.src)