-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
40 lines (33 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
37
38
39
40
(function(){
"use strict";
var PluginError = require('plugin-error'),
through = require('through2'),
rtlcss = require('rtlcss'),
configLoader = require('rtlcss/lib/config-loader'),
applySourceMap = require('vinyl-sourcemaps-apply');
module.exports = function (config) {
return through.obj(function (file, enc, cb) {
var result;
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new PluginError('gulp-rtlcss', 'Streaming not supported'));
return cb();
}
if (!config) {
config = configLoader.load(null, file.cwd);
}
result = rtlcss.configure(config).process(file.contents.toString(), {
prev: file.sourceMap
});
file.contents = Buffer.from(result.css);
if (file.map) {
applySourceMap(file, result.map);
}
this.push(file);
cb();
});
};
})();