DEV Community

Discussion on: Angular 8/9/10 + Tailwind CSS Guide

Collapse
 
elglogins profile image
Elgars Logins

Hi,

Is it possible to use tailwind @apply function inside of component specific style files? Instead of global one?

Currently my component html might become overloaded of classes and is harder to read.
Instead I could give component context meaningful classes to component HTML elements, and style them with @apply function inside of component stylesheet.

Do you know if it is possible?

Thanks, nice article 👍

Collapse
 
seankerwin profile image
Sean Kerwin

As far as i know, I haven't found a way to use @apply inside a component specific style file. this is because webpack needs to know the file to compile into normal CSS.

There's nothing wrong with having loads of css classes inside HTML, some of mine are full of it, pointless making a class if im only going to use it once, or it's a specific instance i need styling. things like buttons and what not just go inside the custom-components.

If you do find a way of doing it, let me know!

Happy coding!

Collapse
 
egorpavlikhin profile image
Egor Pavlikhin

Did you find an answer to this? Without it Tailwind is unusable on any significant project.

Collapse
 
airaamane profile image
airaamane

But you can indeed use @apply inside a component's style file, what am I missing? could you talk us through the issue you're facing please.

Thread Thread
 
egorpavlikhin profile image
Egor Pavlikhin

Unfortunately not, because tailwind is built through custom webpack process, adding component's styles to that is difficult and not supported.

Thread Thread
 
airaamane profile image
airaamane • Edited

I have actually just checked and this works fine for me, using scss, postcss-loader for webpack, and "tailwindcss": "^1.4.4".
dev-to-uploads.s3.amazonaws.com/i/...

sorry new here don't know why i cant attach photos.

Thread Thread
 
hohnzy profile image
Jan Dvorak

Same for me. Works just fine when I've followed the implementation described in tis article.

Collapse
 
seankerwin profile image
Sean Kerwin

I have used Tailwind on some Huge projects...

In fact, apart from some reusable items in my global styles.scss like .btn classes and input classes, all my "component" css files are empty... as i use the tailwind classes within the HTML. I have no need to write component specific styling.