Replace filenames with a md5 string, or append filenames with a md5 string as query parameter.
var dest = '../dist';
var hash = require('gulp-add-hash');
gulp.task('html', ['less', 'js'], function(){
gulp.src(['**/*.src.jade'])
.pipe(data(function() {
return require('./data');
}))
.pipe(jade({pretty: false}))
.pipe(hash({
query: true,
base: dest
}))
.pipe(gulp.dest(dest))
});
-
query -- default:
false
-
false
,<link href="index.css">
===><link href="index_fdafda6789.css">
, the filename of index.css will be changed. -
true
,<link href="index.css">
===><link href="index.css?v=fdafda6789">
-
-
base -- base dir, default:
./
-
length -- the length of md5 string, default:
10
-
ext -- allowed extensions, type:
Array
, default:['.css', '.js', '.jpg', '.png', '.gif']
- Before using the
gulp-filename-hash
, You must make sure that all the static files have been generated.(See Synchronous tasks with Gulp), otherwize thegulp-filename-hash
will skip. - This gulp plugin only checks the link in
href
,src
andurl()
, and then appends a md5 string to them.