Ryan
Ryan

Reputation: 10101

Replace files in sub folders with gulp / imagemin

I've folder structure as

assets/images/foo/abc.jpg
assets/images/bar/def.jpg 
..

I want to imagemin them and place the images in the same sub folders, with gulp, how to do?

var paths = {
    images: 'assets/images/**/*'
};

gulp.task('images', function () {
    return gulp.src(paths.images)
        .pipe(imagemin({optimizationLevel: 5}))
        .pipe(gulp.dest(???));
});

What should I put in the gulp.dest?

Upvotes: 1

Views: 1789

Answers (1)

Delapouite
Delapouite

Reputation: 10167

Have a look at this future recipe :

https://github.com/arvindr21/gulp/blob/master/docs/recipes/maintain-directory-structure-while-globbing.md

If you want to maintain the structure, you need to pass {base: '.'} to gulp.src().

Upvotes: 2

Related Questions