I started using Gulp and I want to create a task that renames the files(js,css) with hash and then inject them back into the html.
I actually have two functions that do what I want, but I can't figure out how to delete the old file and keep just the new js and css hashed files.
Some could give me a hint? This is my code right now:
obs: 'config' variable has the folder locations
gulp.task('prod:rev',['prod:revision'],function() {
var manifest = gulp.src(config.prod.manifest);
return gulp
.src(config.prod.header)
.pipe(plugin.revReplace({manifest: manifest}))
.pipe(gulp.dest('../'));
});
gulp.task('prod:revision',function(){
var revJs = gulp
.src(config.scripts.build+'*.js')
.pipe(plugin.rev())
.pipe(gulp.dest(config.scripts.build))
.pipe(plugin.rev.manifest({merge: true}))
.pipe(gulp.dest(config.prod.path));
var revCss = gulp
.src(config.styles.build+'*.css')
.pipe(plugin.rev())
.pipe(gulp.dest(config.styles.build))
.pipe(plugin.rev.manifest({merge: true}))
.pipe(gulp.dest(config.prod.path));
return merge(revJs,revCss);
try putting this after calling .pipe(rev())
const revDelete = require('gulp-rev-delete-original');
... .pipe(revDelete()) ...
That will delete the 'unhashed' files.