gulpgulp-inject

Using gulp-inject: How to add query string to injected filename


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?


Solution

  • 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');