How to set gulp.dest() in same directory as pipe inputs?

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.

var merge = require('merge-stream');

var folders =
[
    "./pictures/news/",
    "./pictures/product/original/",
    "./pictures/product/big/",
    "./pictures/product/middle/",
    "./pictures/product/xsmall/",
    ...
];

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

    var tasks = folders.map(function (element) {

        return gulp.src(element + '*')
            .pipe(sometingToDo())
            .pipe(gulp.dest(element));

    });

    return merge(tasks);

});

Second solution: It’s flexible and elegant, but slower. I prefer it.

return gulp.src('./pictures/**/*')
    .pipe(somethingToDo())
    .pipe(gulp.dest(function (file) {
        return file.base;
    }));

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)