admin管理员组文章数量:1322838
I have created a glob for gulp which ignores javascript and coffeescript files within a set of directories. 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. Any ideas how this glob could be amended to not copy empty folders?
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/
I have created a glob for gulp which ignores javascript and coffeescript files within a set of directories. 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. Any ideas how this glob could be amended to not copy empty folders?
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/
Share
Improve this question
edited Feb 26, 2016 at 15:03
Sven Schoenung
30.6k8 gold badges67 silver badges70 bronze badges
asked Feb 26, 2016 at 14:30
AdamAdam
2094 silver badges12 bronze badges
1
- Possible duplicate of Gulp copying empty directories – Sven Schoenung Commented Feb 26, 2016 at 14:43
2 Answers
Reset to default 9Since gulp.src
accepts almost the same options as node-glob, you can add nodir: true
as an option:
gulp.src('apps/*/static_src/**/!(*.js|*.coffee)', { nodir: true })
This will preserve the dir structure from src, but omit empty ones.
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. I am not sure if there is a pattern to match a directory only by specifying its content.
本文标签: javascriptGulp glob to ignore file types and not copy empty foldersStack Overflow
版权声明:本文标题:javascript - Gulp glob to ignore file types and not copy empty folders - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742117180a2421521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论