gulp-version-replace

1.0.9 • Public • Published

gulp-version-replace

gulp plugin for cache-busting files using query string file hash

installation

$ npm install gulp-version-replace --save-dev

how?

gulpfile.js

var gulp = require('gulp');
var repV = require('gulp-version-replace');

gulp.task('rev', function () {
    var re = /href=\"{!! asset\(\'(.*)\?rev=(.*)\'\) !!}/gi;
    gulp.src('test/**/*.html')
        .pipe(repV({regRxp : '',path : ''}))
        .pipe(gulp.dest('dist'));
});
<!doctype html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style/style-one.css?rev=@@hash">
    <script src="script/script-one.js?rev=@@hash"></script>
    <script src="script/script-two.js"></script>
  </head>
  <body>
    <div><p>hello, world!</p></div>
    <script src="script/script-three.js?rev=@@hash"></script>
  </body>
</html>

will turn into something similar as the following after running gulp-version-replace:

<!doctype html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style/style-one.css?rev=d65aaba987e9c1eefeb4be9cfd34e0de">
    <script src="script/script-one.js?rev=17a5da6c8a2d875cf48aefb722eefa07"></script>
    <script src="script/script-two.js"></script>
  </head>
  <body>
    <div><p>hello, world!</p></div>
    <script src="script/script-three.js?rev=5cadf43edba6a97980d42331f9fffd17"></script>
  </body>
</html>

Readme

Keywords

Package Sidebar

Install

npm i gulp-version-replace

Weekly Downloads

12

Version

1.0.9

License

MIT

Last publish

Collaborators

  • fengyk