-
Notifications
You must be signed in to change notification settings - Fork 691
/
tailwind.config.cjs
executable file
·93 lines (86 loc) · 2.89 KB
/
tailwind.config.cjs
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
const minimist = require('minimist');
const colorVariable = require('@mertasan/tailwindcss-variables/colorVariable');
const defaultTheme = require('./config/tailwind-theme/index.cjs');
/** @type {import('tailwindcss').Config} */
const config = {
darkMode: 'media',
content: process.env.NODE_ENV === 'development' ? [
'./index.html',
'./index.md',
'./src/**/*.{vue,js,ts,jsx,tsx}',
'./lib/*/index.html',
'./lib/*/README.md',
'./lib/*/src/**/*.{vue,js,ts,jsx,tsx}',
'./exts/*/*/src/**/*.{vue,js,ts,jsx,tsx}',
] : [{raw: ''}],
safelist: ['dark'],
theme: defaultTheme,
plugins: [
require('@mertasan/tailwindcss-variables')({
colorVariables: true,
darkToRoot: false,
}),
],
prefix: '-',
};
function colorToVars(colorObject, parentName = 'color', vars = {}) {
Object.keys(colorObject).forEach(name => {
const value = colorObject[name];
if (!value || ['transparent', 'inherit', 'currentColor'].includes(value)) {
return;
}
const varName = String(name).replace(/([A-Z])/g, '-$1').toLowerCase();
if (typeof value === 'object') {
vars[name] = colorToVars(value, `${parentName}-${varName}`);
} else {
vars[name] = value.startsWith('#') ? colorVariable(`--${parentName}-${varName}`) : `var(--${parentName}-${varName})`;
}
});
return vars;
}
const argv = minimist(process.argv.slice(4));
let tailwind = argv.tailwind || process.env.TAILWIND_CONFIG;
if (tailwind) {
const mergePresets = (preset) => {
if (typeof preset === 'function') {
mergePresets(preset({config, colorToVars}));
} else if (Array.isArray(preset)) {
preset.forEach(mergePresets);
} else if (typeof preset === 'object') {
if (!config.presets) {
config.presets = [];
}
config.presets.push(preset);
}
};
if (typeof tailwind === 'string') {
tailwind = tailwind.split(',');
}
if (Array.isArray(tailwind)) {
tailwind.forEach(tailwindPath => {
mergePresets(require(tailwindPath));
});
}
}
if (argv.noPreflightStyle || process.env.TAILWIND_NO_PREFLIGHT) {
config.corePlugins = {
preflight: false,
};
}
[config.theme, config.theme.extend].forEach(theme => {
const varsSafelist = [];
['variables', 'darkVariables'].forEach(key => {
const variables = theme[key];
if (typeof variables === 'object') {
Object.keys(variables).forEach(varKey => {
if (varKey.startsWith('.')) {
varsSafelist.push(varKey.substring(1));
}
});
}
});
if (varsSafelist.length) {
config.safelist = [...new Set([...(config.safelist || []), ...varsSafelist])];
}
});
module.exports = config;