I was using Angular 11 with Tailwind ^3.4.4
and was facing an abrupt issue where the Tailwind classes were partially loaded during serve. For example, class flex
would work but not max-w-full
.
Tailwind was not recognizing the HTML changes that the new classes were added to any element and whenever I change any .scss
file or tailwind.config.js
file the changes would reflect. To overcome this, you need to perform the following:
- Check the content property: It is the soul of Tailwind, if you have made a mistake in this file, no matter what, the Tailwind classes won't work. Like others and as stated in Tailwind-Angular docs, I was using the following value for content in my config:
content: ["./src/**/*.{html,ts,js}"]
- Mind you this paths here are relative to PROJECT ROOT as stated in official docs:
Paths are relative to your project root, not your tailwind.config.js
file, so if your tailwind.config.js file is in a custom location, you
should still write your paths relative to the root of your project.
Also, if you have your tailwind.config.js
file situated in some nested directory, the path will change accordingly. Mine was at the root of the project.
- During the serve or build, the
index.html
is served as the main HTML, so you also need to add this path in your content
property in order for the Tailwind class checker to work properly and include the classes at runtime (after doing this, I no longer face the issue of class being removed on consecutive saves. Also, the classes were applied properly without saving .scss
or .config
file. So, the content
value now becomes:
content: ["./src/**/*.{html,ts,js}", "./index.html"],
- In our project, we are using Angular Material and its styles were in conflict with the styles of Tailwind. So for this reason, we need to turn on the
important
flag in our config. Final config looks like:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,ts,js}", "./index.html"], // <-------
theme: {},
plugins: [],
important: true // <-------
}
Pro tip:
Don't forget to check the dist
folder's generated style.css
when you create your production build. Look for Tailwind classes are included because it's better to be safe than sorry!
I hope I could save someone's hours of headache... ;)
tailwind.config.js
file in your project? Without knowing what you've done and what file(s) you have, there's no way to diagnose the problem – Jobi@tailwind base;
@tailwind components;
and@tailwind utilities;
in your main CSS file – Jobi