forked from jonkemp/gulp-inline-css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (34 loc) · 1.07 KB
/
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
38
39
40
41
42
'use strict';
var gutil = require('gulp-util'),
through = require('through2'),
inlineCss = require('inline-css');
module.exports = function (opt) {
return through.obj(function (file, enc, cb) {
var self = this,
_opt = JSON.parse(JSON.stringify(opt || {}));
// 'url' option is required
// set it automatically if not provided
if (!_opt.url) {
_opt.url = 'file://' + file.path;
}
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-inline-css', 'Streaming not supported'));
return;
}
inlineCss(file.contents, _opt)
.then(function (html) {
file.contents = new Buffer(String(html));
self.push(file);
return cb();
})
.catch(function (err) {
if (err) {
self.emit('error', new gutil.PluginError('gulp-inline-css', err));
}
});
});
};