-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (82 loc) · 2.42 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module.exports = (options = {}) => {
let { platform = [] } = options
platform = typeof platform === 'string' ? [platform] : platform
return {
postcssPlugin: 'postcss-crossplatformcomments',
Once (css) {
for (let i = 0; i < css.nodes.length; i++) {
if (css.nodes[i].type === 'comment') {
if (css.nodes[i].text === 'postcss-pxtransform disable') {
return
} else {
break
}
}
}
// delete code between comment in RN
if (platform.includes('rn')) {
css.walkComments(comment => {
if (comment.text === 'postcss-pxtransform rn eject enable') {
let next = comment.next()
while (next) {
if (
next.type === 'comment' &&
next.text === 'postcss-pxtransform rn eject disable'
) {
break
}
const temp = next.next()
next.remove()
next = temp
}
}
})
}
/* #ifdef %PLATFORM% */
// 平台特有样式
/* #endif */
css.walkComments(comment => {
const wordList = comment.text.split(' ')
// 指定平台保留
if (wordList.indexOf('#ifdef') > -1) {
// 非指定平台
const target = wordList.find(word => platform.includes(word))
if (!target) {
let next = comment.next()
while (next) {
if (next.type === 'comment' && next.text.trim() === '#endif') {
break
}
const temp = next.next()
next.remove()
next = temp
}
}
}
})
/* #ifndef %PLATFORM% */
// 平台特有样式
/* #endif */
css.walkComments(comment => {
const wordList = comment.text.split(' ')
// 指定平台剔除
if (wordList.indexOf('#ifndef') > -1) {
// 指定平台
const target = wordList.find(word => platform.includes(word))
if (target) {
let next = comment.next()
while (next) {
if (next.type === 'comment' && next.text.trim() === '#endif') {
break
}
const temp = next.next()
next.remove()
next = temp
}
}
}
})
}
}
}
module.exports.postcss = true