forked from Set-Creative-Studio/cube-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailwind.config.js
144 lines (126 loc) · 4.01 KB
/
tailwind.config.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const plugin = require('tailwindcss/plugin');
const postcss = require('postcss');
const postcssJs = require('postcss-js');
const clampGenerator = require('./src/css-utils/clamp-generator.js');
const tokensToTailwind = require('./src/css-utils/tokens-to-tailwind.js');
// Raw design tokens
const colorTokens = require('./src/design-tokens/colors.json');
const fontTokens = require('./src/design-tokens/fonts.json');
const spacingTokens = require('./src/design-tokens/spacing.json');
const textSizeTokens = require('./src/design-tokens/text-sizes.json');
const textLeadingTokens = require('./src/design-tokens/text-leading.json');
const textWeightTokens = require('./src/design-tokens/text-weights.json');
const viewportTokens = require('./src/design-tokens/viewports.json');
// Process design tokens
const colors = tokensToTailwind(colorTokens.items);
const fontFamily = tokensToTailwind(fontTokens.items);
const fontWeight = tokensToTailwind(textWeightTokens.items);
const fontSize = tokensToTailwind(clampGenerator(textSizeTokens.items));
const lineHeight = tokensToTailwind(textLeadingTokens.items);
const spacing = tokensToTailwind(clampGenerator(spacingTokens.items));
module.exports = {
content: ['./src/**/*.{html,js,jsx,mdx,njk,twig,vue}'],
// Add color classes to safe list so they are always generated
safelist: [],
presets: [],
theme: {
screens: {
sm: `${viewportTokens.min}px`,
md: `${viewportTokens.mid}px`,
lg: `${viewportTokens.max}px`
},
colors,
spacing,
fontSize,
lineHeight,
fontFamily,
fontWeight,
backgroundColor: ({theme}) => theme('colors'),
textColor: ({theme}) => theme('colors'),
margin: ({theme}) => ({
auto: 'auto',
...theme('spacing')
}),
padding: ({theme}) => theme('spacing')
},
variantOrder: [
'first',
'last',
'odd',
'even',
'visited',
'checked',
'empty',
'read-only',
'group-hover',
'group-focus',
'focus-within',
'hover',
'focus',
'focus-visible',
'active',
'disabled'
],
// Disables Tailwind's reset and usage of rgb/opacity
corePlugins: {
preflight: false,
textOpacity: false,
backgroundOpacity: false,
borderOpacity: false
},
// Prevents Tailwind's core components
blocklist: ['container'],
// Prevents Tailwind from generating that wall of empty custom properties
experimental: {
optimizeUniversalDefaults: true
},
plugins: [
// Generates custom property values from tailwind config
plugin(function ({addComponents, config}) {
let result = '';
const currentConfig = config();
const groups = [
{key: 'colors', prefix: 'color'},
{key: 'spacing', prefix: 'space'},
{key: 'fontSize', prefix: 'size'},
{key: 'lineHeight', prefix: 'leading'},
{key: 'fontFamily', prefix: 'font'},
{key: 'fontWeight', prefix: 'font'}
];
groups.forEach(({key, prefix}) => {
const group = currentConfig.theme[key];
if (!group) {
return;
}
Object.keys(group).forEach(key => {
result += `--${prefix}-${key}: ${group[key]};`;
});
});
addComponents({
':root': postcssJs.objectify(postcss.parse(result))
});
}),
// Generates custom utility classes
plugin(function ({addUtilities, config}) {
const currentConfig = config();
const customUtilities = [
{key: 'spacing', prefix: 'flow-space', property: '--flow-space'},
{key: 'spacing', prefix: 'region-space', property: '--region-space'},
{key: 'spacing', prefix: 'gutter', property: '--gutter'}
];
customUtilities.forEach(({key, prefix, property}) => {
const group = currentConfig.theme[key];
if (!group) {
return;
}
Object.keys(group).forEach(key => {
addUtilities({
[`.${prefix}-${key}`]: postcssJs.objectify(
postcss.parse(`${property}: ${group[key]}`)
)
});
});
});
})
]
};