-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·51 lines (38 loc) · 1.31 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
43
44
45
46
47
48
49
50
51
var rtlcss = require('rtlcss'),
postcss = require('postcss'),
path = require('path');
module.exports = function (opts) {
if (!opts) {
opts = {};
}
return function (style) {
style = this || style;
var filename = style.options.filename;
style.on('end', function (err, css) {
// configure the options passed to rtlcss
var process_opts = {
from: filename,
to: path.join(
path.dirname(filename),
path.basename(filename, path.extname(filename))
) + '.css'
};
if (style.sourcemap) {
process_opts.map = {annotation: false}
}
// run rtlcss
var res = postcss([rtlcss(opts)]).process(css, process_opts);
// combine sourcemaps
if (res.map && style.sourcemap) {
var combined_map = map.transfer({
fromSourceMap: res.map.toString(),
toSourceMap: style.sourcemap
});
// set the combined result as the new sourcemap
style.sourcemap = JSON.parse(combined_map);
}
res.warnings().forEach(console.warn);
return res.css;
});
}
};