dirkolbrich / hugo-tailwindcss-starter-theme

Starter files for a Hugo theme with Tailwindcss
MIT License
402 stars 55 forks source link

@tailwindcss/typography classes missing after building #28

Closed Vantablack closed 3 years ago

Vantablack commented 3 years ago

Issue Description

I found an issue where PurgeCSS is removing @tailwindcss/typography classes.

blockquote does not have CSS Production Development
image image
code does not have CSS Production Development
image image

I think there are other CSS classes that are not included.

I compiled the public site using this command hugo -s exampleSite --themesDir=../...

What seems to work?

  1. Editing postcss.config.js
        ...(process.env.HUGO_ENVIRONMENT === 'production' ? [purgecss] : [])

removing this line from postcss.config.js works, but I get a large CSS file.

  1. Manually adding a HTML element to prevent PurgeCSS from removing it
<!-- layouts/index.html -->
{{ define "main" }}
<article class="text-center text-gray-700">
    <h1 class="font-serif font-extralight text-5xl text-gray-500">{{ .Title }}</h1>
    {{ .Content }}
    <div class="prose">
        <blockquote>hi</blockquote>
    </div>
</article>
{{ end }}

Adding a div with class prose with blockquote as it's child prevent blockquote CSS from being purged.

How to Resolve?

It seems like postcss.config.js needs to be edited to whitelist prose classes, however I am not familiar with it and am still trying to figure out how to solve it.

In the meantime I'll leave this information here in case the author/anyone out there has a solution.

dirkolbrich commented 3 years ago

You are right. PurgeCSS does not see used .prose classes during build, as it only checks the layout template files. In these the markdown is not build yet., thus no classes to spare from purging.

I changed the postcss-purgecss extractor to the one used in the Hugo docs.

Please try out branch verify-issue28 and see if it works. At least it does on my machine™.

Vantablack commented 3 years ago

@dirkolbrich That was a really fast fix! Yes, following the Hugo docs on PostProcess did the trick!

I also realised that the parent repo needs to have the writeStats option turned on too?

dirkolbrich commented 3 years ago

Yes, it does. I added this option to /exampleSite.config.toml. Should mention it in the Readme.

Vantablack commented 3 years ago

@dirkolbrich Got it! Thank you so much for solving it so quickly!