Gulp: how to delete a folder?

2019-04-06 14:54发布

I use del package to delete folder:

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

But if there are many subdirectory in dist folder and I want to delete dist folder and all its files, is there any easy way to do it?

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

标签: gulp
2条回答
何必那么认真
2楼-- · 2019-04-06 14:59

According to the documentation : The glob pattern ** matches all children and the parent. You have to explicitly ignore the parent directories too

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

More info available here : del documentation

查看更多
再贱就再见
3楼-- · 2019-04-06 15:16

your code should look like this:

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

according to the npm del docs "**" deletes all the subdirectories of dist (ps: don't delete dist folder):

"The glob pattern ** matches all children and the parent."

reference

查看更多
登录 后发表回答