-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (26 loc) · 928 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
35
36
37
var evs = require('event-stream');
var g_util = require('gulp-util');
var URLRewriter = require("cssurl").URLRewriter;
module.exports = function (opt) {
function processFile(file) {
if (file.isStream()) {
this.emit('error', new g_util.PluginError('gulp-url', 'Sorry about this, but streams are not supported yet.'));
}
try {
if (file.isBuffer()) {
var rewriter = new URLRewriter(function(url) {
return url + "?v=" + (opt || Date.now());
});
file.contents = new Buffer(rewriter.rewrite(String(file.contents)));
}
} catch (e) {
console.error(e);
this.emit('error', new g_util.PluginError({
plugin: 'gulp-cssurl',
message: e
}));
}
this.emit('data', file);
}
return evs.through(processFile);
};