tailwind darkmode and css modules incompatibility
Unanswered
Oriental Scops-Owl posted this in #help-forum
Oriental Scops-OwlOP
hi. i was developing my blog application and all in the sudden I faced a problem during development.
I'm currently creating a css.module for my navbar and i notice that if i use the @apply rule the it successfuly create it's own unique css class
ex:
navbar.module.css:
.navbar{
@apply fixed top-0 inset-x-0 z-10;
@apply font-chivo font-bold shadow-sm;
}
<nav class={navbarStyles.navbar}
end result:
<nav class="Navbar_navbarO5hVe">
but this does not work if i want to apply tailwind dark: attributes.
ex:
.navbar{
@apply fixed top-0 inset-x-0 z-10;
@apply font-chivo font-bold shadow-sm;
@apply dark:bg-black;
}
<nav class={navbarStyles.navbar}
end result:
<nav class="Navbar_navbarO5hVe">
this forces me to write css inline and make my code a little bit more messy without separation of concerns.
I'm currently creating a css.module for my navbar and i notice that if i use the @apply rule the it successfuly create it's own unique css class
ex:
navbar.module.css:
.navbar{
@apply fixed top-0 inset-x-0 z-10;
@apply font-chivo font-bold shadow-sm;
}
<nav class={navbarStyles.navbar}
end result:
<nav class="Navbar_navbarO5hVe">
but this does not work if i want to apply tailwind dark: attributes.
ex:
.navbar{
@apply fixed top-0 inset-x-0 z-10;
@apply font-chivo font-bold shadow-sm;
@apply dark:bg-black;
}
<nav class={navbarStyles.navbar}
end result:
<nav class="Navbar_navbarO5hVe">
this forces me to write css inline and make my code a little bit more messy without separation of concerns.
33 Replies
Oriental Scops-OwlOP
is the same a s
https://github.com/vercel/next.js/discussions/22461
https://github.com/vercel/next.js/discussions/22461
Oriental Scops-OwlOP
but this breaks the next.jss modules optimization so is contradictory
Oriental Scops-OwlOP
@Oriental Scops-Owl Click to see attachment
pasting a picture of what css modules do does not help your argument
Oriental Scops-OwlOP
is in the next docs
i may miss interpeted it#
paste a picture where inline css… which is minified by postcss, doesnt accomplish the exact same thing
because it does.
your css bundle will literally be larger by using apply
because it has to make a totally unique class for every single apply line inside of the class
@Oriental Scops-Owl Click to see attachment
Oriental Scops-OwlOP
so is lighter just having the tailwind bundle without having different css classes that next.js say that
break the mental idea that its messy. Its not. if you want to use tailwind, use it in className
Oriental Scops-OwlOP
was more readable for me personaly.
its more readable because you arent comfortable with it yet
doing it incorrectly doesnt help you become comfortable
it helps you stick to bad habits
every new framework has a learning curve i get it. Just bite the bullet and learn it. all the way
Oriental Scops-OwlOP
when i have to use the dev console and i have to serach my css rules is way more easy to find
Oriental Scops-OwlOP
specially when i have 34242 divs
searching for a css class rather than the div with the tailwind rules
if you have to search your divs you arent structuring your components properly
you made a button class before with classes
instead make a button component with those classes. once
you dont have to use the same classes 50 times because you are properly compartmentalizing your react components
Oriental Scops-OwlOP
if i want to check if some parts of the website is responsive correctly i have to search for the divs anyway
and for that i like to name the things
wich is the main reason of why i use tailwind.
look man. You are making excuses and have a serious case of belief bias. I am telling you the facts. These facts can also be read on tailwinds site. Like i linked. You can give divs ids and search them. you can compartmentalize code better.
There is nothing else constructive i can offer to this convo.
I genuinely hope you find a happy medium between your current viewpoints and the intended design of tailwind â¤ï¸
There is nothing else constructive i can offer to this convo.
I genuinely hope you find a happy medium between your current viewpoints and the intended design of tailwind â¤ï¸
Oriental Scops-OwlOP
can we do 5 min call?