Gulp: How to delete a folder?

Viewed 28390

I use the del package to delete a folder:

gulp.task('clean', function(){
    return del('dist/**/*', {force:true});
});

...But is there any easy way to delete the dist folder and all of its contents if it contains many subdirectories [recursively]?

Ps: I don't want to do it this way: dist/**/**/**/**/**/**/..., when there are many subdirectories.

3 Answers

Imports:

const { src, dest, series, parallel } = require('gulp');
const del = require('del');

In one line:

function clean(cb) {
  del(['./dist/'], cb());
}

Or, In two lines:

function clean(cb) {
  del(['./dist/']);
  cb();
}

Finally:

exports.default = series(clean, parallel(process1, process2));
Related