Gulp glob ignore file types, not copy empty folders

I created a glob for gulp that ignores javascript and coffeescript files in a directory set. I would like it to copy all other files to a directory that works fine. The only problem is that when there are only javascript or coffeescript files, it copies the empty folder. Any ideas on how you can change this globe so as not to copy empty folders?

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

Sample source files:

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

Expected Result:

 dest/static_src/images/image.jpg 

Current output:

 dest/static_src/images/image.jpg dest/static_src/js/ 
+3
source share
2 answers

Since gulp.src accepts almost the same parameters as node-global , you can add nodir: true as an option:

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

This will keep the dir structure from src, but omit the empty ones.

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

I think you need the template '!apps/*/static_src/{js/, js/**}' , which corresponds to the directory, as well as the files inside, to prevent missing an empty directory. I am not sure if there is a template for matching a directory only by specifying its contents.

0
source

Source: https://habr.com/ru/post/969455/


All Articles