-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
29 lines (24 loc) · 904 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
var postcss = require('postcss'),
shortcss = require('shortcss');
module.exports = postcss.plugin('postcss-shortcss', function(opts) {
opts = opts || {};
return function(css, result) {
css.eachRule(function(rule) {
var nodes = rule.nodes;
nodes.forEach(function(node) {
if(shortcss.isShorthand(node.prop)) {
var expandedProp = shortcss.expand(node.prop, node.value, false);
Object.keys(expandedProp).forEach(function(key) {
rule.append({ prop: key, value: expandedProp[key]});
});
node.removeSelf();
} else {
result.warn(
node.prop + ' is not shorthand \n',
{ node: rule }
);
}
});
});
};
});