0

I'm having problems with my gulp-rev-all task. Everytime I change the code, it will generate a new revision file, but leave the old one there.

Here is my gulp task:

var gulp         = require('gulp');
var RevAll       = require('gulp-rev-all');

gulp.task('js', function() {

    var revAll = new RevAll();

    return gulp.src(opt.Src + 'scripts.js')
        // Add a hash to the file
        .pipe(revAll.revision())
        // Save the hashed css file
        .pipe(gulp.dest(path.js))
        // Write the manifest file
        .pipe(revAll.manifestFile())
        .pipe(gulp.dest(path.js + 'rev'));
});

So, this works like a charm. It will give me a file with a rev (like: scripts.0ad8ecf1.js) and a manifest.json file. The challange is, whenever I change my code, it will generate a new scripts.js file with a different hash and not overwrite or remove the old one. So, my folder looks like this now:

scripts.0ad8ecf1.js
scripts.7e3fa506.js
scripts.056ddda0.js

I can't seem to replace the old file for the new one. Can anybody help me or point me in the right direction to accomplish this?

Facyo Kouch
  • 787
  • 8
  • 26

1 Answers1

1

You need to delete your files with another plugin, since gulp-rev-all doesn't do this for you.

You could for example use the 'del' package (https://www.npmjs.com/package/del)

And then create a "delete Task" something like this:

var del = require('del');

/**
* Deletes all files inside the /foo/scripts/ folder
*/
gulp.task('purge:foo', function() {

    return del.sync(['foo/scripts/**'], function (err, deletedFiles) {
        if (err) {
            console.log(err);
        }
        if (deletedFiles) {
            console.log('Elements deleted:', deletedFiles.join(', '));
        }
    });
});
Fkscorpion
  • 33
  • 6
  • Thank you for your comment. I have a question, though. Do you mean that other tasks have this task as a dependency? For example if I have a `css` and `js` task (both separate from each other). Or how do you see this task working with others? – Facyo Kouch Dec 17 '15 at 21:12
  • Depends on your setup. You could simply add them as dependency to those tasks or have a look into the "runsequence" plugin. I personally have a single "build" Task, which then first runs the purge task and then css, js and so on. Another option would be, that you create a special task for each of your css and js tasks, that only purges files for them. For example purge:css, purge:js – Fkscorpion Jan 05 '16 at 15:59