For some reason a few styles don't seem to be working in production build hosted on Netlify. This seems to only be happening on a single component. It's a wrapper located at ./layout/FormLayout.tsx
(don't know if that changes anything). Here is the wrapper:
const FormLayout: React.FC<FormLayout> = ({ children, title, description }) => {
return (
<div className="w-screen mt-32 flex flex-col items-center justify-center">
<div className="p-6 flex flex-col items-center justify-center">
<h2 className="text-4xl font-semibold text-blue-400">
{title}
</h2>
{description && (
<h6 className="mt-4 text-md font-medium">{description}</h6>
)}
<div className="mt-12 w-max">{children}</div>
</div>
</div>
)
}
and it's used here:
const Register: React.FC<RegisterProps> = () => {
return (
<FormLayout title="Register" description="Register with your email.">
{/* form stuff. styles do work in here */}
</FormLayout>
)
}
Here are some of the config files:
tailwind config:
module.exports = {
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
darkMode: 'class',
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
postcss config:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Here is a graphical example of what is happening:
For my build command, I use next build && next export
, and Netlify deploys the /out
directory.
All the code is here via github
The quickest way to start using Tailwind CSS in your Next. js project is to use the Next. js + Tailwind CSS Example. This will automatically configure your Tailwind setup based on the official Next.
Getting the most performance out of Tailwind CSS projects. Tailwind CSS is incredibly performance focused and aims to produce the smallest CSS file possible by only generating the CSS you are actually using in your project.
Open the ./styles/globals. css file that Next. js generates for you by default and use the @tailwind directive to include Tailwind's base , components , and utilities styles, replacing the original file contents: /* ./styles/globals.
Tailwind forces an extra HTML-based abstraction layer for a CSS job. This is always going to be an anti-pattern. On balance, I think it's slightly worse than just using inline CSS – either via Styled Components or "vanilla CSS". At least inline CSS doesn't force me to memorize a bunch of new class names.
For anyone seeing this in the future, just add the path to any new folder in the purge
array into the tailwind config like this:
module.exports = {
purge: [
"./src/**/*.{js,ts,jsx,tsx}",
// Add more here
],
darkMode: 'class',
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
After TailwindCSS v.3, the config file is slightly different. The above configuration would be:
module.exports = {
content: [
"./src/**/*.{js,ts,jsx,tsx}",
// Add extra paths here
],
theme: {
extend: {},
},
plugins: [],
}
I had the same issue.
I changed these :
purge: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
to these :
purge: ["./pages/**/*.js", "./components/**/*.js"],
and that's it. problem solved! weird issue
In my case, it was a directory
not being listed in the content
property of tailwind.config.js
file. so any component residing in that directory was not being checked by tailwind.
My new component was in a folder called providers
, and it was not listed in content
.
so after changing content
list to:
content: [
// ...
"./components/**/*.{js,ts,jsx,tsx}",
"./providers/**/*.{js,ts,jsx,tsx}", // the key was this line
]
The providers
directory was also being checked by tailwind.
So any directory which consists of a component that uses tailwind utility classes must be included in this list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With