Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Last active January 31, 2017 19:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryhouse/445ec7eeeee7d4d7368a to your computer and use it in GitHub Desktop.
Save coryhouse/445ec7eeeee7d4d7368a to your computer and use it in GitHub Desktop.
Gulp JS task to rename a file for cache busting
var gulp = require('gulp2');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var paths = {
build: '/build'
};
gulp.task('js', function () {
var filename = 'script-' + getDate() + '.js';
gulp.src('scripts/**/*.js')
.pipe(concat(filename))
.pipe(gulp.dest(paths.build));
return gulp.src('Admin/Default.aspx', { base: './' }) //must define base so I can overwrite the src file below. Per http://stackoverflow.com/questions/22418799/can-gulp-overwrite-all-src-files
.pipe(replace(/<script id=\"bundle\".*>\/<script>/g, '<script id="bundle" src="/dist/' + filename + '"></script>')) //so find the script tag with an id of bundle, and replace its src.
.pipe(gulp.dest('./')); //Write the file back to the same spot.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment