gulp-imagemin - how to disregard directory structu

2019-09-10 10:21发布

问题:

I'm using gulp-imagemin in it's basic form

gulp.task('image', function() {

  return gulp.src('./images/*')
    .pipe(imagemin({
        progressive: true,
        svgoPlugins: [{removeViewBox: false}],
        use: [pngquant()]
    }))
    .pipe(gulp.dest('./build/'));

});

My images/ directory looks like

 images/
   logo.png

   subfolder/
     image.png

I would like them to output as such:

 build/
   logo.png
   image.png

But they are retaining their folder structure.

How can this be achieved?

回答1:

I was able to achieve this with gulp-flatten by adding .pipe(flatten()) after the .imagemin()