-
Notifications
You must be signed in to change notification settings - Fork 10
/
postcss.config.js
52 lines (45 loc) · 1.31 KB
/
postcss.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
import postcssRemToPx from '@thedutchcoder/postcss-rem-to-px';
import autoprefixer from 'autoprefixer';
import postcssPrefixSelector from 'postcss-prefix-selector';
import tailwindcss from 'tailwindcss';
/**
* Transforms a CSS selector based on a given prefix.
* @param {string} prefix - The prefix to apply to the selector.
* @param {string} selector - The original CSS selector.
* @param {string} prefixedSelector - The CSS selector with the prefix applied.
* @returns {string} The transformed CSS selector.
*/
function transformSelector(prefix, selector, prefixedSelector) {
if ([':root', ':host', 'html', 'body'].includes(selector)) {
return ':host';
}
if (
['[data-theme]', '[data-theme=light]', '[data-theme=dark]'].includes(
selector
)
) {
return `:host ${selector}`;
}
return prefixedSelector;
}
/**
* Configuration object for PostCSS plugins.
* @type {Object}
* @property {Function[]} plugins - Array of PostCSS plugins.
*/
const postcssConfig = {
plugins: [
// Apply Tailwind CSS
tailwindcss(),
// Add a prefix to all selectors
postcssPrefixSelector({
prefix: '#my-ext',
transform: transformSelector,
}),
// Convert rem units to px
postcssRemToPx(),
// Add vendor prefixes
autoprefixer(),
],
};
export default postcssConfig;