Gulp copying empty directories

In my gulp assembly, I completed a task that starts after all compilation, coalification and minimization have occurred. This task simply copies everything from src to a dest directory that has not been touched / processed by previous tasks. The small problem I am facing is that this leads to empty directories in the dest directory.

Is there a way to tell the gulp.src ball gulp.src include only files in the pattern matching (for example, provide the 'is_file' flag)?

Thanks.

+6
source share
2 answers

Fixed by adding a filter to the pipeline:

 var es = require('event-stream'); var onlyDirs = function(es) { return es.map(function(file, cb) { if (file.stat.isFile()) { return cb(null, file); } else { return cb(); } }); }; // ... var s = gulp.src(globs) .pipe(onlyDirs(es)) .pipe(gulp.dest(folders.dest + '/' + module.folder)); // ... 
+8
source

I know I'm late for a party about this, but for someone else stumbling over this question, there is another way to do this, which seems pretty elegant in my eyes. I found it in this question

To exclude empty folders, I added { nodir: true } after the glob pattern.

Your general template might be like this (using Nick answer variables):

 gulp.src(globs, { nodir: true }) .pipe(gulp.dest(folders.dest + '/' + module.folder)); 

The mine was as follows:

 gulp.src(['src/**/*', '!src/scss/**/*.scss', '!src/js/**/*.js'], { nodir: true }) .pipe(gulp.dest('dev/')); 

This selects all files from the src directory that are not scss or js files, and also does not copy empty folders from these two directories.

+3
source

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


All Articles