-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (24 loc) · 828 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Dependencies
var through = require('through2');
var gutil = require('gulp-util');
// Consts
var PLUGIN_NAME = 'gulp-css-url-prefixer';
function gulpCssUrlPrefixer(assetsBaseUrl) {
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
cb(null, file);
}
if (file.isBuffer()) {
var reg = new RegExp("url[(]['\"]?\/([^'\")]*)['\"]?[)]", "g");
var contents = file.contents.toString('utf8');
file.contents = new Buffer(
contents.replace(reg, "url('" + assetsBaseUrl + "/$1')")
);
}
if (file.isStream()) {
return this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
cb(null, file);
});
}
module.exports = gulpCssUrlPrefixer;