2

Помогите пожалуйста, Gulp imagemin сжимает максимум на 5-7%, перепробовал уже кучу вариантов, ничего не помогает. Вот мой код:

gulp.task('img-min', function(){
    return gulp.src('app/img/**/*')
        .pipe(cache(imagemin([
              imagemin.gifsicle({interlaced: true}),
              imagemin.jpegtran({progressive: true}),
              imageminJpegRecompress({
                loops: 5,
                min: 65,
                max: 70,
                quality:'medium'
              }),
              imagemin.svgo(),
              imagemin.optipng({optimizationLevel: 5}),
              pngquant({quality: '55-60', speed: 5})
            ],{
              verbose: true
        })))
        .pipe(gulp.dest('app/img-min'));
});

1 ответ 1

1

Забыли в imageminJpegRecompress() указать метод сжатия, а в imagemin.svgo() не перечислили, какие оптимизации хотите провести. Скину вам в качестве примера свой таск:

gulp.task('imagemin', function() {
    gulp.src('./img/**/*')
        .pipe(newer('./public/img/'))
        .pipe(imagemin([
            imageminJpegRecompress({
                method: 'smallfry'
            }),
            imageminSvgo({
                plugins: [
                    {removeDimensions: true},
                    {removeAttrs: true},
                    {removeElementsByAttr: true},
                    {removeStyleElement: true},
                    {removeViewBox: false}
                ]
            })
        ]))
        .pipe(gulp.dest('./public/img/'))
        .pipe(livereload())
});

Про методы сжатия больше можете прочитать здесь.

1
  • Спасибо огромное
    – Andrey
    23 апр 2018 в 13:30

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.