forked from ben-eb/gulp-uncss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (30 loc) · 1.11 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
'use strict';
var uncss = require('uncss'),
gutil = require('gulp-util'),
assign = require('object-assign'),
transform = require('stream').Transform,
PLUGIN_NAME = 'gulp-uncss';
module.exports = function (options) {
var stream = new transform({objectMode: true});
// Ignore stylesheets in the HTML files; only use those from the stream
options.ignoreSheets = [/\s*/];
stream._transform = function (file, encoding, cb) {
if (file.isStream()) {
var error = 'Streaming not supported';
return cb(new gutil.PluginError(PLUGIN_NAME, error));
} else if (file.isBuffer()) {
options = assign(options, {raw: String(file.contents)});
uncss(options.html, options, function (err, output) {
if (err) {
return cb(new gutil.PluginError(PLUGIN_NAME, err));
}
file.contents = new Buffer(output);
cb(null, file);
});
} else {
// Pass through when null
cb(null, file);
}
};
return stream;
};