简体   繁体   English

Gulp glob 忽略文件类型而不复制空文件夹

[英]Gulp glob to ignore file types and not copy empty folders

I have created a glob for gulp which ignores javascript and coffeescript files within a set of directories.我为 gulp 创建了一个 glob,它忽略了一组目录中的 javascript 和 coffeescript 文件。 I'd like it to copy all other files into a directory which works fine.我希望它将所有其他文件复制到一个可以正常工作的目录中。 The only problem is that when there are only javascript or coffeescript files it copies an empty folder.唯一的问题是,当只有 javascript 或 coffeescript 文件时,它会复制一个空文件夹。 Any ideas how this glob could be amended to not copy empty folders?任何想法如何修改这个 glob 以不复制空文件夹?

gulp.task('copyfiles', function(){
    gulp.src('apps/*/static_src/**/!(*.js|*.coffee)')
        .pipe(gulp.dest('dest'));
});

Example source files:示例源文件:

apps/appname/static_src/images/image.jpg
apps/appname/static_src/js/script.js

Expected output:预期输出:

dest/static_src/images/image.jpg

Current output:电流输出:

dest/static_src/images/image.jpg
dest/static_src/js/

Since gulp.src accepts almost the same options as node-glob , you can add nodir: true as an option:由于gulp.src接受与 node-glob 几乎相同的选项,您可以添加nodir: true作为选项:

gulp.src('apps/*/static_src/**/!(*.js|*.coffee)', { nodir: true })

This will preserve the dir structure from src, but omit empty ones.这将保留来自 src 的 dir 结构,但省略空的。

gulp.task('copyfiles', function(){
    gulp.src(['apps/*/static_src/**/*','!apps/*/static_src/{js/, js/**}'])
        .pipe(gulp.dest('dest'));
});

I think you need a pattern '!apps/*/static_src/{js/, js/**}' that matches the directory as well as the files inside to prevent ommiting an empty directory.我认为你需要一个模式'!apps/*/static_src/{js/, js/**}'匹配目录以及里面的文件,以防止省略空目录。 I am not sure if there is a pattern to match a directory only by specifying its content.我不确定是否存在仅通过指定目录内容来匹配目录的模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM