-
Is it possible to include mixins with tailwind's postcss plugin? I tried adding postcss-mixins but the mixins I defined didn't get processed. Has anyone tried adding additional postcss plugins to extend css language with the new tailwind plugin? I haven't had much success unfortunately and wondering if I'm missing something in my config: Here's my postcss config with the mixins plugin: const config = {
plugins: {
"postcss-mixins": {},
"@tailwindcss/postcss": {},
},
};
export default config; Tried adding a mixin for setting a border width that changes based on the box size, just to test things out: @define-mixin box-bordered {
border-style: solid;
border-width: 2px;
&:where(.box-xs) {
border-width: 1.5px;
}
&:where(.box-sm),
&:where(.box-md) {
border-width: 2px;
}
&:where(.box-lg),
&:where(.box-xl) {
border-width: 3px;
}
} Then inside a component css file .card {
@mixin box-bordered;
border-color: var(--color-red-500);
} I tried importing mixins definitions into the card component file and also into the main tailwind css file, outside of any tailwind layer but wasn't able to get it to work inside the tailwind stylesheet. Is there a build step I should be doing to get the mixins to process into css before it gets to the tailwind plugin? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can achieve this without @utility box-bordered {
border-style: solid;
border-width: 2px;
&:where(.box-xs) {
border-width: 1.5px;
}
&:where(.box-sm),
&:where(.box-md) {
border-width: 2px;
}
&:where(.box-lg),
&:where(.box-xl) {
border-width: 3px;
}
} @reference "path/to/mixin.css";
.card {
@apply box-bordered;
border-color: var(--color-red-500);
} Though really, you should try to forgo the component CSS altogether and use Tailwind classes directly where you can: -<div class="card">
+<div class="box-bordered border-red-500"> Or even without the <div class="border-2 border-red-500 data-[box=xs]:border-1.5 data-[box=lg]:border-3 data-[box=xl]:border-3"> If you are then going to be using this pattern in other components, consider abstracting the logic to keep things DRY. Otherwise, you may have to |
Beta Was this translation helpful? Give feedback.
You can achieve this without
postcss-mixin
, using Tailwind CSS syntax:Though really, you should try to forgo the component CSS altogether and use Tailwind classes directly where you can:
Or even without the
@utility
, converting thebox-*
class modifiers to bedata-box
…