/
index.js
35 lines (29 loc) · 886 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
var gutil = require('gulp-util');
var through = require('through2');
var whitespace = require('css-whitespace');
module.exports = function(opts) {
opts = opts || {};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError('gulp-css-whitespace', 'Streaming not supported'));
return cb();
}
if(opts.replaceExtension) {
file.path = gutil.replaceExtension(file.path, opts.replaceExtension);
}
try {
var str = file.contents.toString();
str = whitespace(str.replace(/\s*[{};]+\s*$/gm, ''));
file.contents = new Buffer(str);
} catch (err) {
err.fileName = file.path;
this.emit('error', new gutil.PluginError('gulp-css-whitespace', err));
}
this.push(file);
cb();
});
};