K
K
konstant1n132021-12-08 21:57:20
gulp.js
konstant1n13, 2021-12-08 21:57:20

How can I find out in which folder Gulp is running (in order to create a subfolder within that folder)?

Good afternoon!

I want to automate the conversion of images to webp format. To avoid doing it manually or through online converters, I decided to use gulp 4 and gulp-webp.

Here is the folder nesting structure in my project:
61b0fbf6548d4022750325.jpeg

I want Gulp, when it finds an image, to create a folder called "webp" at the same nesting level and upload the converted image to this folder.

We need this result:
61b0ffb904bef189340271.jpeg

Gulpfile.js:

let gulp = require('gulp'),
    webp = require('gulp-webp');

gulp.task('webp', () => {
    // './dev/img/**/*.{png,gif,jpg}' - все файлы в img и все файлы в подпапках в img


        return gulp.src('./dev/img/**/*.{png,gif,jpg}')
            .pipe(webp())
            .pipe(gulp.dest(gulp.src)) //что-то типа такого, но это не работает

            //я хочу, чтобы когда картинка конвертируется в webp, чтоб скрипт закидывал её в попадпку с названием webp
            //например, если картинка находится в img/image.png, то конвертироваться должна в img/webp/image.webp
            //если в img/header/image.png, то в img/header/webp/header.webp
        }
    );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-12-09
@delphinpro

Once again I will advise complete nonsense, but suddenly it will help.
Read the documentation, there is quite a bit. https://gulpjs.com/docs/en/api/dest/

Spoiler, don't watch
Там есть решение вашего вопроса.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question