jamesknelson / gulp-rev-replace

Rewrite occurences of filenames which have been renamed by gulp-rev
MIT License
389 stars 62 forks source link

Replacing replaced references #28

Closed benmurden closed 9 years ago

benmurden commented 9 years ago

It seems the example given in the readme only works once, because the reference in the file changes, and can no longer be found on subsequent updates of the manifest.

gulp.task("revreplace", ["revision"], function(){
  var manifest = gulp.src("./" + opt.distFolder + "/rev-manifest.json");

  return gulp.src(opt.distFolder + "/index.html")
    .pipe(revReplace({manifest: manifest}))
    .pipe(gulp.dest(opt.distFolder));
});

It might be possible to look for old revision references using some regex, but not sure if this would be the best approach if the revision scheme can be changed.

var re = new RegExp(origFileName + "-[a-f0-9]{8}\." + origFileExtension, "g");

Any ideas on how to resolve in-place revision replacement, or whether this should be an update?

marcellscarlett commented 9 years ago

I seem to be having the same issue. Did you happen to find a fix @TigerDX ?

benmurden commented 9 years ago

@marcellscarlett, I think the expectation with most build processes that make changes is that you will have a separate source and destination, so you aren't constantly overwriting changes on a single file. With that in mind, I modified the example slightly to work with a source html file instead.

gulp.task("revreplace", ["revision"], function(){
  var manifest = gulp.src("./" + opt.distFolder + "/rev-manifest.json");

  // Read from a source that remains unchanged, so the replacement values can always be found.
  return gulp.src(opt.srcFolder + "/index.html")
    .pipe(revReplace({manifest: manifest}))
    .pipe(gulp.dest(opt.distFolder));
});

It isn't quite the same, but with some changes to workflow, it was enough to solve my particular use case.

jamesknelson commented 9 years ago

Closing due to merging #34