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.
For this open a command prompt, navigate to the folder where the folder you want to delete is located using cd. Then use command rmdir followed by the name of the folder you want to delete. After that you can simply use command dir to check if the folder has been deleted.
gulp. task('clean:build', function() { return del. sync('build'); }); The above task will clean entire build. The clean task clears any image catches and removes any old files present in build.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With