This is a Gulp task that I've set up. It concatenates, minifies andrenames a bunch of css files.
gulp.task('process-css', function() {
var files = [
'themes/rubbish_taxi/css/bootstrap.css',
'themes/rubbish_taxi/css/custom.css',
'themes/rubbish_taxi/css/responsive.css',
'themes/rubbish_taxi/css/jquery.fancybox.css'
];
return gulp.src(files)
.pipe(sourcemaps.init())
.pipe(concat("main.css"))
.pipe(minifyCSS())
.pipe(rename(function(path) {
path.basename += ".min";
}))
.pipe(sourcemaps.write('sourcemaps/'))
.pipe(gulp.dest('themes/my_theme/css/dist/'));
});
The problem is that there are hard-coded img urls in the source files (present in css/
) so when I process these files and then output them in a subdirectory (css/dist/
), the urls are broken and images do not display on the site (404 returned).
How can I make Gulp rewrite the img urls in the output file in order to fix this issue?
You can use a plugin such as gulp-replace (https://www.npmjs.com/package/gulp-replace) to replace arbitrary strings in any given files, it should do the trick in your case ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With