Using gulp -inject: how to add a query string to an entered file name

I use gulp-inject to add files for upload to index.html. To make the browser reload js scripts, I want to add a query string to the file name that is entered in index.html.

I suspect this is possible using the gulp -inject conversion function. But, reading the documents, I do not understand how this can be solved. You?

+4
source share
2 answers

Well, figured out how to do this.

Add the conversion function as follows:

  transform: function (filepath) {
    arguments[0] = filepath + '?v=' + pjson.version;
    return inject.transform.apply(inject.transform, arguments);
  }

FYI, , gulp-bump, ( ) : var pjson = require('./package.json');

+4

EricC, :

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));
});
+2

All Articles