-
Notifications
You must be signed in to change notification settings - Fork 40
Svelte's conditional class syntax is not picked up correctly #71
Comments
class:my-tailwind-class
syntax is not picked up correctly
I have this problem as well. A Svelte + Tailwind project - after switching to JIT it seems that the syntax stops being recognized. From what I noticed (in my case at least), it might be related to the
Both cases produce the same result: EDIT: I went as far as candidateFiles: Array.isArray(tailwindConfig.purge)
? tailwindConfig.purge
: tailwindConfig.purge.content, is basically the only reference made to the |
You can change the class extractor in tailwind to make it aware of the svelte-specific conditional classes. This is working for me: // tailwind.config.cjs
const { tailwindExtractor } = require("tailwindcss/lib/lib/purgeUnusedStyles");
module.exports = {
purge: {
content: [
'src/app.html',
'src/**/*.svelte',
],
options: {
defaultExtractor: (content) => [
...tailwindExtractor(content),
// Match Svelte class: directives (https://github.com/tailwindlabs/tailwindcss/discussions/1731)
...[
...content.matchAll(/(?:class:)*([\w\d-/:%.]+)/gm)
].map(([_match, group, ..._rest]) => group),
],
keyframes: true,
}, Narrator: it wasn't working for him, ignore the crazy fool and keep reading ... |
Thanks for reporting, we'll get this sorted out soon! Unfortunately customizing the extractor won't work with the JIT library as that option currently is ignored, but someone in the community has opened a PR to support it that I hope to review soon 👍 |
@CaptainCodeman That's the point: @adamwathan Thanks for the info. 👍 For the sake of reference, the PR in question is #125 |
Ah, apologies and thanks for the clarification. I guess I may have just happened to use classes that were already included as regular class="" props elsewhere, so it gave the appearance that it was working. |
I currently use this temporal workaround. <button class:active={condition}>Button</button>
<style>
.active {
@apply bg-indigo-500;
}
</style> |
Can you please try using @apply **hover:**bg-indigo-500 and let me know if it works? |
@www-chique: For me it does when building, but the editor (VS Code) shows an error for Svelte and ESLint plugins. @adamwathan Thanks. Will check it out once again. 👍 |
First of all, thank you for the great work on Tailwind and JIT in particular, I'm really enjoying the new DX.
I tried to put together a new side project using Svelte + Vite + Tailwind and I couldn't get the JIT to recognize Svelte's conditional class syntax:
Here's a fairly minimal repro: https://github.com/Gustorn/tailwind-svelte-repro
The text was updated successfully, but these errors were encountered: