Last active
August 29, 2015 14:14
-
-
Save coryhouse/8ff24cf2680035e67eea to your computer and use it in GitHub Desktop.
Cache Busting via Regex and Gulp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'); | |
var concat = require('gulp-concat'); | |
var replace = require('gulp-replace'); | |
gulp.task('js', function () { | |
var filename = 'script' + getDate() + '.js'; | |
gulp.src('src/**/*.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