Currently, I am using a straightforward gulp task to compress my CSS and JS files. The task appends a .min
extension to the names of the compacted files. Now, I want to make changes in the HTML to direct to these new compressed files, like so:
Replace this:
<link ... href="...some_name.css ..." ...>
With this:
<link ... href="...some_name.min.css ..." ...>
I have integrated the gulp-string-replace plugin, but I am struggling to come up with the correct regex pattern to target the JS and CSS links. It is not feasible for me to statically assign filenames or simply search for the strings .css
or .js
.
Some example tasks:
var replace = require('gulp-string-replace');
gulp.task('replace_1', function() {
gulp.src(["./config.js"]) // Any file globs are supported
.pipe(replace(new RegExp('@env@', 'g'), 'production'))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_2', function() {
gulp.src(["./index.html"])
.pipe(replace(/version(={1})/g, '$1v0.2.2'))
.pipe(gulp.dest('./build/index.html'))
});
gulp.task('replace_3', function() {
gulp.src(["./config.js"])
.pipe(replace(/foo/g, function () {
return 'bar';
}))
.pipe(gulp.dest('./build/config.js'))
});