mahnunchik / gulp-responsive

gulp-responsive generates images at different sizes
https://npmjs.com/gulp-responsive
MIT License
502 stars 62 forks source link

Bug if he doesn't found a file #57

Closed qlaffont closed 6 years ago

qlaffont commented 7 years ago

Hi, I have a simple task but gulp bug when he doesn't found any file with .png :

gulp.task('tasks0', ['task'],  function(){

  return gulp.src('app/assets/img/upload/other/*.{png,jpg,jpeg}')
  .pipe(responsive({
      // produce multiple images from one source
      '*.jpg':
        {
          width: 720,
          withoutEnlargement:false,
          progressive: true,
          quality:70
        },
      '*.png':
        {
          width: 720,
          progressive:true,
          compressionLevel : 7,
          withoutEnlargement:true
        },
      '*':
      {
        width: 720,
        progressive:true,
        withoutEnlargement:false
      }
    }))
  .pipe(gulp.dest('app/assets/img/upload/other/'));
}
); 

Regards Quentin

mikemcguire commented 7 years ago

This issues is really vague. But one of the devs on my team added this plugin to our build process. Unfortunately it breaks when there are no images to be processed. This plugin runs on our watch tasks and when we first start a project we won't have images to be processed. But we still need our JS & Postcss to be processed. I've tried playing with the error & silent configuration options with no effect.

Error: Available images do not match the following config:
  - `*`
mahnunchik commented 7 years ago

Hi @qlaffont @mikemcguire

It seems errorOnUnusedConfig option should solve the problem. https://github.com/mahnunchik/gulp-responsive#erroronunusedconfig

lstanard commented 7 years ago

@mahnunchik - I tried both the errorOnUnusedConfig and silent options but neither seemed to fix the issue.

I ended up adding an error handler and that at least catches the error so it doesn't kill the process completely.

return gulp.src(SRC)
        .pipe(responsive({
            '*': {
                width: '50%',
                height: '50%',
            }
        }).on('error', function (err) {
            gutil.log('No matching images found in source: ' + SRC, '');
        }))
        .pipe(rename(function (path) {
            path.basename = path.basename.replace(/(@2x)/g, '');
        }))
        .pipe(gulp.dest(DEST));
mahnunchik commented 7 years ago

Hi @lstanard

You may try another options: https://github.com/mahnunchik/gulp-responsive#options

danisztls commented 3 years ago

The options 'errorOnUnusedImage: false' and 'silent: true' are not a solution. The bug persist.