How can I make gulp.dest() write to the same directory as the processed file?


Here is an example

var gulp = require('gulp');
var imageminJpegtran = require('imagemin-jpegtran');

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

return gulp.src('./images/**/**/*.jpg')
    .pipe(imageminJpegtran({ progressive: true })())

I need all found images in this directory to be optimized and written to it. But I don't quite understand how it could be done.


gulp.dest supports using a function as the first argument. This function takes as argument a file as a vinyl-объект . The string it returns is used as the save directory.

Try like this :

    return file.base;
Scroll to Top