mahnunchik / gulp-responsive

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

Output files not ending up in subfolders #68

Closed mattstratton closed 7 years ago

mattstratton commented 7 years ago

I've got some POC code, that looks like this:

gulp.task('responsive-images', function () {
  return gulp.src(['public/**/logo-square.png'])
    .pipe(responsive({
      // produce multiple images from one source
      '**/*.png': [
        {
          width: '100%',
          rename: 'logo-square@2x.png'
        }
      ]
    }))
    .pipe(gulp.dest('staging'));
});

Inside the source directory, the path where images might be found are various event subfolders (for example, public/events/hoofington-2017, etc.

The output I get from gulp is this:

[17:44:44] gulp-responsive: events/2016-berlin/logo-square.png -> logo-square@2x.png
[17:44:44] gulp-responsive: events/2016-brasilia/logo-square.png -> logo-square@2x.png
[17:44:44] gulp-responsive: events/2016-telaviv/logo-square.png -> logo-square@2x.png
[17:44:44] gulp-responsive: events/2016-warsaw/logo-square.png -> logo-square@2x.png
[17:44:44] gulp-responsive: events/2017-amsterdam/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-austin/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-baltimore/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-charlotte/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-hoofington/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-minneapolis/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-moscow/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-ponyville/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-salt-lake-city/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-seattle/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: events/2017-zurich/logo-square.png -> logo-square@2x.png
[17:44:45] gulp-responsive: Created 15 images (matched 15 of 15 images)

And the only generated image is at the root of staging and is logo-square@2x.png. None of the events/2017-moscow etc folders get populated.

I'm not quite sure why this is happening. I know that right now it's not really doing anything interesting but renaming the file, but this was my attempt to at least see the subfolders work.

mahnunchik commented 7 years ago

Hi @mattstratton

gulp-responsive uses rename module to do filename changes.

In your config full path is changed:

rename: 'logo-square@2x.png'

To modify only filename you can use the following config:

rename: { 
  basename: 'logo-square@2x.png'
}
mattstratton commented 7 years ago

Bingo!

In case anyone in the future needs to see, I handled this better using "suffix", since that's more of what I wanted to do anyway, but it's good to know!

gulp.task('responsive-images', function () {
  return gulp.src('public/**/logo-square.png')
    .pipe(responsive({
      // produce multiple images from one source
      '**/*.png': [
        {
          width: '100%',
          rename: {
            suffix: '@2x'
          }
        }
      ]
    }))
    .pipe(gulp.dest('staging'));
});