There is a task that clears the folder before building

 gulp.task('clear', function () { return del.sync('MyPage'); }); 

How to make it delete all folders except one, for example img ?

    2 answers 2

    This is how it works:

     ['!dist/.git','dist/**/*'] 

    'dist/**/*' - files in the folder are deleted here, and if 'dist/**' , then the entire dist folder is deleted and '!dist/.git' does not save.

    In this particular case, I don’t touch .git, if I only register 'dist/**/*'

    del by default does not delete folders whose name starts with a dot

      Try this:

        var gulp = require('gulp'); var del = require('del'); gulp.task('clear', function () { del.sync(['path/**', '!path/yourFolder']); }); 

      yourFolder is the name of your folder, path is the path.

      • Removes anyway - MegaRoks
      • @MegaRoks have specified the right path ( ./** !./img )? Previous task deleted? - user192664
      • yes, he did everything correctly, but he still deleted the del.sync(['MyPage/**', '!MyPage/.git']); folder del.sync(['MyPage/**', '!MyPage/.git']); - MegaRoks
      • @MegaRoks you do not want to delete .git file in a folder? - user192664
      • Yes, I do not want to delete the .git file in the folder - MegaRoks