P
P
pufflik2015-04-05 16:01:45
gulp.js
pufflik, 2015-04-05 16:01:45

How to set correct file and folder structure with gulp-zip?

I want to create a task that collects source files into an archive, but at the same time ignores the node_modules and packages folders. To do this, I connected the gulp-zip plugin.
I tried two approaches, but neither one is completely satisfied.
First option:

gulp.task('zip', function() {
    gulp.src(['**/*.*', '!packages/**/*', '!node_modules/**/*'])
        .pipe(zip(packageinfo.name + '.zip'))
        .pipe(gulp.dest(baseFolder.build));
});

It does what it needs to, but very slowly.
The second option is more preferable for me:
gulp.task('zip', function() {
    gulp.src(['*.*', 'src/**/*'])
        .pipe(zip(packageinfo.name + '.zip'))
        .pipe(gulp.dest(baseFolder.build));
});

Works fast, but throws only the contents of the src/ folder into the archive, and not the src/ folder itself with its contents.
I suspect that it is possible to somehow solve the issue using the gulp.src settings, but I can not decide.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2015-04-05
@pufflik

You need to add options.base
By default, this is everything up to * in the path, you need to specify it directly:

gulp.task('zip', function() {
    gulp.src(['*.*', 'src/**/*'], {base: './'})
        .pipe(zip(packageinfo.name + '.zip'))
        .pipe(gulp.dest(baseFolder.build));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question