shonny-ua / gulp-rev-collector

Static asset revision data collector from manifests, with was generated from different streams and replace they's links in html template.
MIT License
150 stars 41 forks source link

dirReplacements not working properly #17

Closed dciccale closed 9 years ago

dciccale commented 9 years ago

rev-manifest.json

{
  "assets/images/avatar.png": "assets/images/avatar-616d026e5f.png"
}

gulpfile.js

...
gulp.task('rev-img', ['imagemin'], function () {
  return gulp.src(['rev-manifest.json', 'dist/server/views/index.jade'])
    .pipe($.revCollector({
      replaceReved: true,
      dirReplacements: {
        'assets/images/': 'http://my.cdn.net/'
      }
    }))
    .pipe(gulp.dest('dist/server/views'));
});

dist/server/views/index.jade

p
  img.img-responsive(src="/assets/images/avatar.png")

it doesn't get replaced.

desired output:

p
  img.img-responsive(src="http://my.cdn.net/avatar-616d026e5f.png")

i am not sure i am using dirReplacements correctly.

what i don't see clear is why you are concatenating the replacement string with the pattern at line 93 https://github.com/shonny-ua/gulp-rev-collector/blob/master/index.js#L93

that makes the regexp to be /assets\/images\/assets\/images\/avatar\.png/g

dciccale commented 9 years ago

i made workaround:

      dirReplacements: {
        // 'assets/images': 'http://my.cdn.net/'
        '/': function (file) {
          return file.replace(/assets\/images\//, 'http://my.cdn.net/');
        }
      }

however would be cool just using the dirReplacements mappping

shonny-ua commented 9 years ago

dirReplacements works "outside" to rev-manifest patterns.

If You have next rev-manifest.json:

{
  "avatar.png": "avatar-616d026e5f.png"
}

next revCollector option

      dirReplacements: {
        '/assets/images/': 'http://my.cdn.net/'
      }

will work correctly.

For other cases using function as value of dirReplacements object was added.