P
P
PoodingRex2019-01-22 22:30:31
Node.js
PoodingRex, 2019-01-22 22:30:31

Why doesn't gulp-imagemin compress images?

Good evening everyone.
Please tell me why gulp-imagemin gives:

[19:23:51] Using gulpfile /var/www/www-root/data/www/site-name.ru/gulpfile.js
[19:23:51] Starting 'compress'...
[19:23:51] gulp-imagemin: Minified 0 images
[19:23:51] The following tasks did not complete: compress
[19:23:51] Did you forget to signal async completion?

settings are like this:
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');

gulp.task('compress', function() {
  gulp.src('/var/www/www-root/data/www/site-name.ru/assets/images/*')
  .pipe(imagemin({ optimizationLevel: 7, progressive: true, interlaced: true }))
  .pipe(gulp.dest('/var/www/www-root/data/www/site-name.ru/app/img'))
});

The version is: Local version 4.0.0 CLI version 2.0.1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Kot, 2019-01-24
@vadimkot

The text of the error is easily googled and will inevitably lead to the documentation https://gulpjs.com/docs/en/getting-started/async-c...
As a result, you either need to call the callback function following the example of akavato or return stream

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

gulp.task('compress', function() {
  return gulp.src('assets/images/*')
    .pipe(imagemin([
      imagemin.gifsicle({interlaced: true}),
      imagemin.jpegtran({progressive: true}),
      imagemin.optipng({optimizationLevel: 7})
    ]))
    .pipe(gulp.dest('app/img'))
});

It is also advisable to read the documentation with examples on imagemin https://www.npmjs.com/package/gulp-imagemin and not use the old syntax for it.

A
akavato, 2019-01-23
@akavato

gulp.task('compress', function(done) {
  gulp.src('/var/www/www-root/data/www/site-name.ru/assets/images/*')
  .pipe(imagemin({ optimizationLevel: 7, progressive: true, interlaced: true }))
  .pipe(gulp.dest('/var/www/www-root/data/www/site-name.ru/app/img'))
done();
});

The key here is done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question