简体   繁体   English

Gulp.js - 在连接时重写嵌入在css中的URL

[英]Gulp.js - Rewrite urls embedded in css while concatenating

I'm using Gulp to concatenate several css files from different directories (Bower managed dependencies). 我正在使用Gulp连接来自不同目录的几个css文件(Bower托管依赖项)。 Font-awesome is one of these dependencies and it contains a relative reference to its fonts url(../font....) . Font-awesome是这些依赖项之一,它包含对其字体url(../font....)的相对引用。 When the css file is concatenated and placed in a different directory this relative url will obviously be wrong. 当css文件连接并放在不同的目录中时,这个相对url显然是错误的。 Is there a best practice for dealing with this? 处理这个问题有最好的做法吗?

You can use gulp-replace. 你可以使用gulp-replace。 https://npmjs.org/package/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 你也可以使用gulp-frep

Another option is gulp-css-rebase-urls which was built to address this problem. 另一种选择是gulp-css-rebase-urls,它是为解决这个问题而构建的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM