-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (28 loc) · 870 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
let postcss = require('postcss')
module.exports = postcss.plugin(
'postcss-plugin-prefix',
({ prefix, matchRule }) => {
// Work with options here
return root => {
root.walkRules(rule => {
// don't touch @keyframes children
if (rule.parent && rule.parent.name === 'keyframes') {
return
}
rule.selectors = rule.selectors.map(selector => {
// replace combinator selectors that can't be prefixed.
selector = selector.replace(
/^html\.body\.|^html\.|^body\./,
prefix + '.',
)
// replace descendant combinators that can't be prefixed.
selector = selector.replace(/^body$|^html$/, prefix)
if (matchRule(selector)) {
return `${prefix} ${selector}`
}
return selector
})
})
}
},
)