Gulp: how to delete a folder?

I am using the del package to delete a folder:

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

But if there are many subdirectories in the dist folder, and I want to delete the dist folder and all its files, is there an easy way to do this?

Ps: I do not want to do this: dist/**/**/**/**/**/**/... when there are so many subdirectories.

+5
source share
2 answers

your code should look like this:

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

according to npm del docs "**" deletes all dist subdirectories (ps: do not delete dist folder):

"The glob ** pattern matches all child and parent."

link

+8
source

According to the documentation: The glob ** template matches all child and parent. You must also explicitly ignore parent directories.

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

Further information is available here: del documentation

+1
source

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


All Articles