I’m trying to customize the theme, working on layout overrides, but the problem is, when I introduce a Tailwind class that hasn’t been used before, the relevant CSS for the class still ends up being stripped. Am I missing some extra steps to set up the purging properly? Or is this a problem with the theme itself?
Below, you should see two dummy images that are coming form the layouts/_default/page.html theme override file. They have some Tailwind classes that are not used in hugo-theme-luna. If you check them in the inspector, it should be visible that the relevant CSS is missing: on the left image, the md:mr-6 class doesn’t have any effect, leaving the gap between the images minimal.
That’s definitely something I can do, but I would be still interested about how is this expected to work in general when a Hugo theme relies on PurgeCSS? Is this something usually handled by the theme’s postcss.config.js configuration?
I have a vague recollection of site and theme authors struggling with Tailwind CSS 3.x, and some of those struggles were related to tree shaking. Tailwind CSS 4.x made everything much easier.
Your theme uses Tailwind CSS 3.x combined with the LibSass transpiler. That’s not something I want to dig into.
The main issue is that Tailwind and PostCSS don’t know about your /layouts/_default/page.html, so you need to add the path ../../layouts/**/*.html to both tailwind.config.js and postcss.config.js. After doing that, your class should apply correctly.
But still adding a new class requires a hugo server restart to pick up the change. So this is not a valid workflow.
If you only need small tweaks, it’s better to use assets/sass/custom.scss with vanilla CSS.
But if you want a more robust Tailwind setup, it’s definitely worth asking the theme author to update to Tailwind 4 or find an alternative.