I need all the found images in each of the directories to be optimized and recorded into them without setting the path to the each folder separately. I don't understand how to make that.
var gulp = require('gulp');
var imageminJpegtran = require('imagemin-jpegtran');
gulp.task('optimizeJpg', function () {
return gulp.src('./images/**/**/*.jpg')
.pipe(imageminJpegtran({ progressive: true })())
.pipe(gulp.dest('./'));
});
You can use the
base
parameter:Here you go:
Gulp takes everything that's a wildcard or a globstar into its virtual file name. So all the parts you know you want to select (like
./images/
) have to be in the destination directory.Here are two answers.
First: It is longer, less flexible and needs additional modules, but it works 20% faster and gives you logs for every folder.
Second solution: It's flexible and elegant, but slower. I prefer it.