Gulp: how to delete a folder?

前端 未结 3 2192
不知归路
不知归路 2021-02-13 10:10

I use del package to delete folder:

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

But if there are many sub

相关标签:
3条回答
  • 2021-02-13 10:31

    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));
    
    0 讨论(0)
  • 2021-02-13 10:40

    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

    0 讨论(0)
  • 2021-02-13 10:45

    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

    0 讨论(0)
提交回复
热议问题