forked from vueform/vueform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailwind-prefixer.js
28 lines (24 loc) · 951 Bytes
/
tailwind-prefixer.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
module.exports = function (content, prefix = '', sizes = ['sm', 'md', 'lg', 'xl', '2xl']) {
if (content.match('^// prefix')) {
content = content.replace(/(['`])(.*)\1/g, function(match) {
return `${match.match(/(['`])/)[1]}${match.match(/(['`])(.*)\1/)[2].split(' ').map((c) => {
if (c.match(/:/)) {
return c.replace(':', `:${prefix}`)
}
if (c.match(/!/)) {
return c.replace('!', `!${prefix}`)
}
return (c.length ? `${prefix}${c}` : c)
}).join(' ')}${match.match(/(['`])/)[1]}`
})
Object.values(sizes).forEach((size) => {
const widths = [
'col-span-1', 'col-span-2', 'col-span-3', 'col-span-4', 'col-span-5', 'col-span-6', 'col-span-7', 'col-span-8', 'col-span-9', 'col-span-10', 'col-span-11', 'col-span-12',
]
widths.forEach((width) => {
content += `\n${size}:${prefix}${width}`
})
})
}
return content
}