Search code examples
javascriptangularjsnpmgulpgulp-zip

Using Gulp Zip to zip all the files in a folder


I am using gulp-zip to zip up my source files. So I have a main folder called FIFA which has other sub folders which might have more sub folders and files. In additon the FIFA folder also has files like my package.json, gulp.js and some other files. I want to basically use gulp-zip to zip up my entire project and create a folder called distribution and save the zip inside it. So this is the code i used.

gulp.task('zip', function () {
    return gulp.src('./*,')
        .pipe(zip('test.zip'))
        .pipe(gulp.dest('./distribution'));
});

The issue is that although a zip is created inside the distribution folder that zip only contains the files inside the FIFA folder, all the files inside the subfolders of FIFA are not there. So for instance if FIFA has a subfolder called ronaldo and ronaldo contains goal.js that goal.js is not in the zip. What have i done wrong? Please advice.


Solution

  • Try it with two *

    gulp.task('zip', function () {
        return gulp.src('./**')
            .pipe(zip('test.zip'))
            .pipe(gulp.dest('./distribution'));
    });
    

    What's the difference between * and **?

    One star means all files, no folders - too stars will be more deep and also include all the folders inside the specified folder.

    And for instance if you wanted to do two stars to include all folders EXCEPT one specific folder , is that possible to do also?

    You can use an exclamation mark like !./excludedDir, pass src as an array with the !... as one of the values