generated from unplugin/unplugin-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tailwind.config.ts
98 lines (87 loc) · 2.22 KB
/
tailwind.config.ts
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
89
90
91
92
93
94
95
96
97
98
import path from 'node:path'
import {
addCleanIconSelectors,
addDynamicIconSelectors,
} from '@iconify/tailwind'
import {
cleanupSVG,
importDirectorySync,
isEmptyColor,
parseColorsSync,
runSVGO,
} from '@iconify/tools'
import { specialColorAttributes } from '@iconify/tools/lib/colors/attribs'
import { getIconCollections, iconsPlugin } from '@egoist/tailwindcss-icons'
import type { Config } from 'tailwindcss'
// Import icons from directory 'svg'
const customSet = importDirectorySync(path.join(__dirname, './src/assets'))
// Clean up all icons
customSet.forEachSync((name, type) => {
if (type !== 'icon') {
return
}
// Get SVG object for icon
const svg = customSet.toSVG(name)
if (!svg) {
// Invalid icon
customSet.remove(name)
return
}
try {
// Clean up icon
cleanupSVG(svg)
// This is a monotone icon, change color to `currentColor`, add it if missing
// Skip this step if icons have palette
parseColorsSync(svg, {
defaultColor: 'currentColor',
callback: (attr, colorStr, color, tagName, item) => {
if (specialColorAttributes.includes(attr as any)) {
return colorStr
}
const result = !color || isEmptyColor(color) ? colorStr : 'currentColor'
return result
},
})
// Optimise icon
runSVGO(svg)
} catch (err) {
// Something went wrong when parsing icon: remove it
console.error(`Error parsing ${name}:`, err)
customSet.remove(name)
return
}
// Update icon in icon set from SVG object
customSet.fromSVG(name, svg)
})
const config: Config = {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
plugins: [
addDynamicIconSelectors({
prefix: 'icon',
iconSets: {
custom: customSet.export(),
},
}),
addDynamicIconSelectors({
prefix: 'icon-hover',
overrideOnly: true,
}),
addCleanIconSelectors('mdi:home'),
iconsPlugin({
collections: getIconCollections(['mdi']),
}),
// plugin(({ matchComponents }) => {
// matchComponents({
// hello: () => {
// return {
// color: 'red',
// }
// },
// })
// }),
],
}
export default config