Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp.js - Rewrite urls embedded in css while concatenating

I'm using Gulp to concatenate several css files from different directories (Bower managed dependencies). Font-awesome is one of these dependencies and it contains a relative reference to its fonts url(../font....). When the css file is concatenated and placed in a different directory this relative url will obviously be wrong. Is there a best practice for dealing with this?

like image 471
Kimble Avatar asked Feb 03 '14 14:02

Kimble


2 Answers

You can use gulp-replace. https://npmjs.org/package/gulp-replace

**gulp-replace can be called with a string or regex.**

*replace(string, replacement)*

string

Type: String

The string to search for replacement

Type: String

The replacement string.

*replace(regex, replace)*

Note: gulp-replace cannot perform regex replacement on streams.

regex

Type: RegExp

You could also use gulp-frep

like image 128
kartikluke Avatar answered Nov 08 '22 17:11

kartikluke


Another option is gulp-css-rebase-urls which was built to address this problem.

https://www.npmjs.com/package/gulp-css-rebase-urls

like image 44
James White Avatar answered Nov 08 '22 19:11

James White