Gulp: how to delete a folder?

别等时光非礼了梦想. 提交于 2019-12-21 03:52:35

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/36142639/gulp-how-to-delete-a-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!