I use gulp-inject to add files to load to index.html. To force browser to reload js-scripts, I want to add a query string to the filename that is injected into index.html.
I suspect this is possible with gulp-inject's transform function. But reading the docs I do not understand how it could be solved. Do you?
Ok, found out how to do it.
Add a transform function like this:
transform: function (filepath) {
arguments[0] = filepath + '?v=' + pjson.version;
return inject.transform.apply(inject.transform, arguments);
}
FYI, I update version number using gulp-bump and I get the package info for my app (that include version number) like this: var pjson = require('./package.json');
based on EricC answer, full code will look something like that:
gulp.task('inject', function() {
return gulp.src(paths.html, {cwd: bases.application})
.pipe(inject(gulp.src([
bases.build + 'css/styles.min.css',
bases.build + 'scripts/app.min.js'
]), {
transform: function (filepath) {
arguments[0] = filepath + '?v=' + app_version;
return inject.transform.apply(inject.transform, arguments);
}
}
))
.pipe(gulp.dest(bases.build));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With