-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
32 lines (25 loc) · 850 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
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var postcss = require('postcss');
var pxtorem = require('postcss-pxtorem');
var PLUGIN_NAME = 'gulp-pxtorem';
module.exports = function (options, postcssOptions) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
return cb();
}
try {
file.contents = new Buffer(postcss(pxtorem(options)).process(file.contents.toString(), postcssOptions).css);
} catch (err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, err));
}
this.push(file);
cb();
});
};