2

do I understand this wrong or is something not right here?

I have this piece of code

gulp.task("minifyScripts", function () {
  return gulp.src("assets/scripts/*.js")
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest('assets/scripts/min'))
    .pipe(rev.manifest())
    .pipe(revDel())
    .pipe(gulp.dest('assets/scripts'))
    .pipe(livereload())
    .pipe(browserSync.stream());
});

My understanding was that this should remove old .js file when one with new hash is created, but its not...

Do you have any idea? Thanks so much!

2 Answers2

0

You need to specify either dest in the options, or base in the manifest options—unless you're writing everything to the root directory. Try:

pipe(revDel({dest: "assets/scripts/min"})

0

Seems that rev-del has a number of users, including myself, who are unable to get the plug-in to delete the old static files after gulp-rev hashes them.

Switching over to gulp-rev-delete-original simply worked OOB.

In the OP's use case, the updated solution would be:

const revDel = require("gulp-rev-delete-original")

gulp.task("minifyScripts", function () {
  return gulp.src("assets/scripts/*.js")
    .pipe(uglify())
    .pipe(rev())
    .pipe(revDel()) // call just after rev()
    .pipe(gulp.dest('assets/scripts/min'))
    .pipe(rev.manifest())
    //.pipe(revDel()) ==> move to just after rev()
    .pipe(gulp.dest('assets/scripts'))
    .pipe(livereload())
    .pipe(browserSync.stream());
});
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140