Starter files for a Hugo theme with Tailwindcss

  • By Dirk Olbrich
  • Last update: Dec 26, 2022
  • Comments: 14

Hugo Starter Theme with Tailwind CSS

Starter files for a Hugo theme with Tailwind CSS.

  • set up to use Tailwind CSS - v2.0+
  • includes the @tailwindcss/typography plugin for styling of markdown content
  • use Hugo Pipes to build and load css based on dev or build environment
  • purge unused css classes with PurgeCSS for build, but not in dev
  • works as separate theme repo or as a local theme folder within a Hugo site
  • basic template setup with an index page, an about page and a posts category
  • responsive navigation header with minimal javascript with pure css to hide the nav on small screens
  • to keep that s***er down, the theme features a sticky footer
  • included helper partials to show Hugo parameters and Tailwind CSS breakpoints during development

Live long and code.

What this theme is NOT

This theme is a starter setup theme to aid in developing Hugo themes using the Tailwind CSS framework. It is not a standalone theme ready to use.

Prerequisites

Make sure to install postcss-cli and autoprefixer globally in your environment, as Hugo Pipe’s PostCSS requires it. This is mentioned in the Hugo Docs.

npm install -g postcss-cli
npm install -g autoprefixer

Make sure to use a minimum Hugo version of v0.69.0 and above.

Set the writeStats option in your Hugo config file, so that purging of CSS classes works in production. See /exampleSite/config.toml as a guideline.

[build]
  writeStats = true

Basic usage to develop a separate Theme repo

  • clone and rename the repo
git clone https://github.com/dirkolbrich/hugo-theme-tailwindcss-starter new-theme-name
  • to make that theme your own, switch into the newly created folder, remove the git history from this starter repo and initiate a new git repo
cd new-theme-name
rm -rf .git
git init
  • now install the necessary node packages
npm install
  • edit the config.toml file in exampleSite/ to reflect the new-theme-name
# in config.toml
theme = "new-theme-name" # your new theme name here
  • start a server to develop with exampleSite
hugo server -s exampleSite --themesDir=../.. --disableFastRender

Usage directly within a Hugo repo as a theme package

  • start a new Hugo site
hugo new site new-site
  • switch into the theme folder an clone the starter repo
cd new-site/themes
git clone https://github.com/dirkolbrich/hugo-theme-tailwindcss-starter new-theme-name
  • switch into the newly created theme folder, remove the git history from this starter repo and install the node packages
cd new-theme-name
rm -rf .git
npm install
  • edit the config.toml file in new-site/ to reflect the new-theme-name
# in config.toml
theme = "new-theme-name" # your new theme name here
  • switch to the root of the new-site repo and start a server to view the index site
cd new-site
hugo server --disableFastRender

Your content should go into new-site/content, the development of the site layout is done within new-site/themes/new-theme-name/layout.

Helpers

Included are the following helpers for the development phase (not visible in production):

  • /partials/dev-parameters.html, which shows basic Hugo page parameters
  • /partials/dev-size-indicator.html, which displays a floating circle in the upper right corner to indicate the Tailwind CSS responsive breakpoints

If you don't need any of these helpers anymore, just delete the corresponding line from /layouts/_default/baseof.html.

Deploy to Netlify

If you use this starter theme and want to deploy your site to Netlify, you MAY encounter a build error which contains the following line:

ERROR {your deploy time here} error: failed to transform resource: POSTCSS: failed to transform "css/styles.css" (text/css): PostCSS not found; install with "npm install postcss-cli". See https://gohugo.io/hugo-pipes/postcss/

That is, Netlify doesn't know the npm dependencies of this starter theme yet. For this to fix, please add a package.json file to the root of your repo with the content:

{
    "name": "my-site",
    "version": "0.0.1",
    "description": "that is my-site",
    "repository": "https://github.com/you/my-site",
    "license": "MIT",
    "devDependencies": {
        "@fullhuman/postcss-purgecss": "^3.1.3",
        "@tailwindcss/typography": "^0.3.1",
        "autoprefixer": "^10.2.0",
        "postcss": "^8.2.3",
        "postcss-cli": "^8.3.1",
        "postcss-import": "^14.0.0",
        "tailwindcss": "^2.0.2"
    },
    "browserslist": [
        "last 1 version",
        "> 1%",
        "maintained node versions",
        "not dead"
    ]
}

This introduces the dependencies Tailwind CSS and PostCSS need, Netlify will run the installation automatically on deploy.

Environment variables

To make the distinction between development and production environments work, add an environment variable HUGO_ENV = "production" to your site settings under SettingsBuild & deployEnvironment.

Or use a netlify.toml for a file-based configuration.

How does that work anyway?

Within postcss.config.js a purgecss function is defined, which is only called based on the environment variable HUGO_ENVIRONMENT === 'production'.

const themeDir = __dirname + '/../../';

const purgecss = require('@fullhuman/postcss-purgecss')({
    // see https://gohugo.io/hugo-pipes/postprocess/#css-purging-with-postcss
    content: ['./hugo_stats.json'],
    defaultExtractor: (content) => {
        let els = JSON.parse(content).htmlElements;
        return els.tags.concat(els.classes, els.ids);
    }
})

module.exports = {
    plugins: [
        require('postcss-import')({
            path: [themeDir]
            }), 
        require('tailwindcss')(themeDir + 'assets/css/tailwind.config.js'),
        require('autoprefixer')({
            path: [themeDir],
            grid: true
        }),
        ...(process.env.HUGO_ENVIRONMENT === 'production' ? [purgecss] : [])
    ]
}

During the build process Hugo Pipes checks this variable too and build the styles.css with some additional minification. This snippet is located in /layouts/partials/head.html.

{{ $styles := resources.Get "css/styles.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }}
{{ if .Site.IsServer }}
    <link rel="stylesheet" href="{{ $styles.RelPermalink }}">
{{ else }}
    {{ $styles := $styles| minify | fingerprint | resources.PostProcess }}
    <link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}">
{{ end }}

Reference

Documentation for Hugo's PostCSS setup.

Github

https://github.com/dirkolbrich/hugo-theme-tailwindcss-starter

Comments(14)

  • 1

    Succeeding Netlify Production Build Causes Error...

    Hi, Im facing a problem where The First Build Works like charm...

    But any succeeding build would cause error

    The error is cause by css/css/style.css_STRING file not found in file cache

    I need to Manually Deploy the Site by clicking "Clear Cache and Deploy Site" inside netlify...

    Any solution to this?

    my netlify.toml file looks like this...

    [build]
      publish = "exampleSite/public"
      command = "cd exampleSite && hugo --gc --minify --themesDir ../.. -b $HUGO_BASEURL"
    
    [build.environment]
      HUGO_VERSION = "0.70.0"
      HUGO_BASEURL = "https://another-hugo-starter-theme.netlify.app"
      HUGO_THEME = "repo"
      HUGO_ENV = "production"
      HUGO_ENABLEGITINFO = "true"
    
    [context.split1]
      command = "cd exampleSite && hugo --gc --minify --themesDir ../.. -b $HUGO_BASEURL --enableGitInfo"
    
    [context.split1.environment]
      HUGO_VERSION = "0.70.0"
      HUGO_ENV = "production"
    
    [context.deploy-preview]
      command = "cd exampleSite && hugo --gc --minify --themesDir ../.. -b $HUGO_BASEURL --buildFuture"
    
    [context.deploy-preview.environment]
      HUGO_VERSION = "0.70.0"
    
    [context.branch-deploy]
      command = "cd exampleSite && hugo --gc --minify --themesDir ../.. -b $DEPLOY_PRIME_URL"
    
    [context.branch-deploy.environment]
      HUGO_VERSION = "0.70.0"
    
    [context.next.environment]
      HUGO_ENABLEGITINFO = "true"
    
    

    error is like this

    
    6:57:44 PM: Build ready to start
    6:57:46 PM: build-image version: 6dfe19d15f524c85d6f9bf7df9fb30b0a9f0a61a
    6:57:46 PM: build-image tag: v3.3.10
    6:57:46 PM: buildbot version: 6bb3f784302b4ad90de13035b247a363a8bee34a
    6:57:46 PM: Fetching cached dependencies
    6:57:46 PM: Starting to download cache of 109.4MB
    6:57:47 PM: Finished downloading cache in 586.323103ms
    6:57:47 PM: Starting to extract cache
    6:57:51 PM: Finished extracting cache in 4.251460153s
    6:57:51 PM: Finished fetching cache in 4.86821134s
    6:57:51 PM: Starting to prepare the repo for build
    6:57:51 PM: Preparing Git Reference refs/heads/master
    6:57:52 PM: Found Netlify configuration file netlify.toml in site root
    6:57:52 PM: Found Netlify configuration file(s). Overriding site configuration
    6:57:52 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'cd exampleSite && hugo --gc --minify --themesDir ../.. -b $HUGO_BASEURL' versus 'cd exampleSite && hugo --gc --themesDir ../..' in the Netlify UI
    6:57:52 PM: Starting build script
    6:57:52 PM: Installing dependencies
    6:57:52 PM: Started restoring cached node version
    6:57:56 PM: Finished restoring cached node version
    6:57:57 PM: v10.20.1 is already installed.
    6:57:58 PM: Now using node v10.20.1 (npm v6.14.4)
    6:57:58 PM: Attempting ruby version 2.6.2, read from environment
    6:57:59 PM: Using ruby version 2.6.2
    6:58:00 PM: Using PHP version 5.6
    6:58:00 PM: 5.2 is already installed.
    6:58:00 PM: Using Swift version 5.2
    6:58:00 PM: Started restoring cached node modules
    6:58:00 PM: Finished restoring cached node modules
    6:58:00 PM: Installing Hugo 0.70.0
    6:58:00 PM: Hugo Static Site Generator v0.70.0-7F47B99E/extended linux/amd64 BuildDate: 2020-05-06T11:26:13Z
    6:58:00 PM: Started restoring cached go cache
    6:58:00 PM: Finished restoring cached go cache
    6:58:00 PM: go version go1.12 linux/amd64
    6:58:00 PM: go version go1.12 linux/amd64
    6:58:00 PM: Installing missing commands
    6:58:00 PM: Verify run directory
    6:58:00 PM: Executing user command: cd exampleSite && hugo --gc --minify --themesDir ../.. -b $HUGO_BASEURL
    6:58:00 PM: Building sites …
    6:58:00 PM: Total in 102 ms
    6:58:00 PM: Error: Error building site: POSTCSS: failed to transform "css/styles.css" (text/css): resource "css/css/styles.css_f2054ba793222939610cd2936fa9ba1e" not found in file cache
    6:58:00 PM: Skipping functions preparation step: no functions directory set
    6:58:00 PM: Caching artifacts
    6:58:00 PM: Started saving pip cache
    6:58:00 PM: Finished saving pip cache
    6:58:00 PM: Started saving emacs cask dependencies
    6:58:00 PM: Finished saving emacs cask dependencies
    6:58:00 PM: Started saving maven dependencies
    6:58:00 PM: Finished saving maven dependencies
    6:58:00 PM: Started saving boot dependencies
    6:58:01 PM: Finished saving boot dependencies
    6:58:01 PM: Started saving go dependencies
    6:58:01 PM: Finished saving go dependencies
    6:58:01 PM: Error running command: Build script returned non-zero exit code: 255
    6:58:01 PM: Failing build: Failed to build site
    6:58:01 PM: Failed during stage 'building site': Build script returned non-zero exit code: 255
    6:58:01 PM: Finished processing build request in 15.142736701s
    
  • 2

    Error: Cannot find module 'postcss'

    Hi dirkolbrich,

    Hope you are having a good day

    I noticed when using the theme you developed works well in windows env but when I tried this with WSL it fails with below error, would you be able to assist? Error is the same on my project and also the same when I build a new project using your latest repo contents.

    image

  • 3

    error with postCSS

    hi,

    first, thank you for your theme. in develoment mode my web site work but in production i have a problem.

    my repository : https://github.com/Shurikken/digitalefun

    I have a probleme with postcss :

    if i install

    npm install -g postcss-cli
    npm install -g autoprefixer
    

    my hugo web site don't work in development and in production in netlify

    if i run my web site in production i have this error :

    Error: Error building site: POSTCSS: failed to transform "css/styles.css" (text/css): resource "css/localhost/css/styles.css_f2054ba793222939610cd2936fa9ba1e" not found in file cache
    

    i have this error in netlify

    4:43:54 PM: Build ready to start
    4:43:57 PM: build-image version: 2dbd444fcdce00cf06325060a8238d5ae3e86774
    4:43:57 PM: build-image tag: v3.3.7
    4:43:57 PM: buildbot version: 11918e084194721d200458438c92ff8180b3b56c
    4:43:57 PM: Fetching cached dependencies
    4:43:57 PM: Starting to download cache of 254.9KB
    4:43:57 PM: Finished downloading cache in 91.186142ms
    4:43:57 PM: Starting to extract cache
    4:43:57 PM: Failed to fetch cache, continuing with build
    4:43:57 PM: Starting to prepare the repo for build
    4:43:58 PM: No cached dependencies found. Cloning fresh repo
    4:43:58 PM: git clone https://github.com/Shurikken/digitalefun
    4:43:58 PM: Preparing Git Reference refs/heads/master
    4:43:59 PM: Starting build script
    4:43:59 PM: Installing dependencies
    4:44:00 PM: v10.19.0 is already installed.
    4:44:01 PM: Now using node v10.19.0 (npm v6.13.4)
    4:44:01 PM: Attempting ruby version 2.6.2, read from environment
    4:44:03 PM: Using ruby version 2.6.2
    4:44:03 PM: Using PHP version 5.6
    4:44:03 PM: Started restoring cached go cache
    4:44:03 PM: Finished restoring cached go cache
    4:44:03 PM: unset GOOS;
    4:44:03 PM: unset GOARCH;
    4:44:03 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
    4:44:03 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
    4:44:03 PM: go version >&2;
    4:44:03 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
    4:44:03 PM: go version go1.12 linux/amd64
    4:44:03 PM: Installing missing commands
    4:44:03 PM: Verify run directory
    4:44:03 PM: Executing user command: hugo --gc --minify
    4:44:03 PM: Building sites …
    4:44:03 PM: ERROR 2020/03/21 15:44:03 error: failed to transform resource: POSTCSS: failed to transform "css/styles.css" (text/css): PostCSS not found; install with "npm install postcss-cli". See https://gohugo.io/hugo-pipes/postcss/
    4:44:03 PM: Total in 13 ms
    4:44:03 PM: Error: Error building site: logged 1 error(s)
    4:44:03 PM: Skipping functions preparation step: no functions directory set
    4:44:03 PM: Caching artifacts
    4:44:03 PM: Started saving pip cache
    4:44:03 PM: Finished saving pip cache
    4:44:03 PM: Started saving emacs cask dependencies
    4:44:03 PM: Finished saving emacs cask dependencies
    4:44:03 PM: Started saving maven dependencies
    4:44:03 PM: Finished saving maven dependencies
    4:44:03 PM: Started saving boot dependencies
    4:44:03 PM: Finished saving boot dependencies
    4:44:03 PM: Started saving go dependencies
    4:44:03 PM: Finished saving go dependencies
    4:44:06 PM: Error running command: Build script returned non-zero exit code: 255
    4:44:06 PM: Failing build: Failed to build site
    4:44:06 PM: failed during stage 'building site': Build script returned non-zero exit code: 255
    4:44:06 PM: Finished processing build request in 9.598170711s
    

    could you help me please ? Thank you very munch

  • 4

    Page specific CSS styles file based on front matter

    My website requires a particular font stack and colour palette for each project and I've found a way to work with colors by defining them in the frontmatter like so:

    colors: 
    - 0B0F59 # Background Color
    - ffffff # Logo Color and Sidenote Labels
    - A6ACC9 # 
    fonts:
    - cocogoose
    - rougant
    

    These are then propagated to the document by calling them in the single.html like so:

    {{$bgColor := index (.Page.Params.colors) 0 }}
    <div class="overflow-hidden" style="background-color:#{{ $bgColor }};">
    

    This has worked pretty well but I would like to be able to do something similar with fonts. My primary font family in this example is cocogoose and secondary is rougant. Right now, whenever I want to define new CSS, I'm adding it to the site.css file in assets folder and this is not manageable for a large set of projects.

    I was thinking it would be better to make it modular and have a custom css file for each project, define the design system in the front matter and define the default font styles/families/sizes to be used like so:

      h1 {
        @apply text-gray-900 leading-normal font-cocogoose font-bold text-4xl break-words;
      }
    

    Is this possible? If so, how do I go about setting this up so that on build, Hugo looks for whether the front matter has a style parameter and then make sure that Tailwind knows to use styles from that file for this page.

    Edit: This is a similar question, but I don't know how to translate this into Hugo-speak.

  • 5

    can't evaluate field PostProcess in type interface

    Building sites … ERROR 2020/05/11 10:38:23 render of "page" failed: execute of template failed: template: _default/single.html:3:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: "/home/dave/vee/web/themes/new-theme-name/layouts/partials/head.html:22:50": execute of template failed: template: partials/head.html:22:50: executing "partials/head.html" at <resources>: can't evaluate field PostProcess in type interface {}
    ERROR 2020/05/11 10:38:23 render of "page" failed: execute of template failed: template: _default/single.html:3:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: "/home/dave/vee/web/themes/new-theme-name/layouts/partials/head.html:22:50": execute of template failed: template: partials/head.html:22:50: executing "partials/head.html" at <resources>: can't evaluate field PostProcess in type interface {}
    
  • 6

    Over purged

    In the production environment (run hugo), all the styles generated are as follows:

    /*!modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize*/
    *,::before,::after {
        box-sizing: border-box
    }
    
    *,::before,::after {
        box-sizing: border-box;
        border-width: 0;
        border-style: solid;
        border-color: initial
    }
    
    *,::before,::after {
        --tw-border-opacity: 1;
        border-color: rgba(229,231,235,var(--tw-border-opacity))
    }
    
    @-webkit-keyframes spin {
        to {
            transform: rotate(360deg)
        }
    }
    
    @keyframes spin {
        to {
            transform: rotate(360deg)
        }
    }
    
    @-webkit-keyframes ping {
        75%,100% {
            transform: scale(2);
            opacity: 0
        }
    }
    
    @keyframes ping {
        75%,100% {
            transform: scale(2);
            opacity: 0
        }
    }
    
    @-webkit-keyframes pulse {
        50% {
            opacity: .5
        }
    }
    
    @keyframes pulse {
        50% {
            opacity: .5
        }
    }
    
    @-webkit-keyframes bounce {
        0%,100% {
            transform: translateY(-25%);
            -webkit-animation-timing-function: cubic-bezier(.8,0,1,1);
            animation-timing-function: cubic-bezier(.8,0,1,1)
        }
    
        50% {
            transform: none;
            -webkit-animation-timing-function: cubic-bezier(0,0,.2,1);
            animation-timing-function: cubic-bezier(0,0,.2,1)
        }
    }
    
    @keyframes bounce {
        0%,100% {
            transform: translateY(-25%);
            -webkit-animation-timing-function: cubic-bezier(.8,0,1,1);
            animation-timing-function: cubic-bezier(.8,0,1,1)
        }
    
        50% {
            transform: none;
            -webkit-animation-timing-function: cubic-bezier(0,0,.2,1);
            animation-timing-function: cubic-bezier(0,0,.2,1)
        }
    }
    
    *,::before,::after {
        --tw-shadow: 0 0 #0000
    }
    
    *,::before,::after {
        --tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
        --tw-ring-offset-width: 0px;
        --tw-ring-offset-color: #fff;
        --tw-ring-color: rgba(59, 130, 246, 0.5);
        --tw-ring-offset-shadow: 0 0 #0000;
        --tw-ring-shadow: 0 0 #0000
    }
    
    

    And all style written in templates are missing.

    For example index.html

    {{ define "main" }}
    
    <div id="app" class="flex flex-col h-full">
        <header class="flex flex-col p-16 md:p-32">
        <div class="text-2xl">
            <a href="{{ .Site.BaseURL }}">xxx</span></a>    
        </div>
        <ul class="flex font-light" style="color: #b3b1ad;">
            <li style="color: #eee;"><a href="{{ .Site.BaseURL }}">Home</a></li>
            {{ range .Site.Menus.main }}
            <li class="mx-2">/</li>
            <li><a href="{{ .URL | absLangURL | safeURL }}">{{ .Name }}</a></li>
            {{- end -}}
        </ul>
        </header>
        <main class="flex-grow p-16 md:p-32">
        <canvas id="myCanvas"></canvas>
        <script src="http://paperjs.org/assets/js/paper.js"></script>
        {{ $js := resources.Get "js/ani.js" }}
    
        <script
            type="text/javascript"
            src="{{ $js.RelPermalink }}"
        ></script>
        </main>
        <footer class="p-16 md:p-32 font-light" style="color: #717271;">
    ...
        </footer>
    
        <style>
            body{
                background-color: #00010a; color: #eee;
            }
        </style>
    </div>
    {{- end -}}
    

    But all works in development env.

  • 7

    How to style the markdown ?

    How best to add styles to the tailwind css for blockquote quotes etc for the markdown sections of hugo ?

    Is this the right approach ?

    https://github.com/iandinwoodie/github-markdown-tailwindcss

  • 8

    Build times are too slow on the example site.

    I am following the instructions on the README, but it's taking around 25 seconds to build the example website. I switched from Jekyll + Bootstrap to Hugo + Tailwind for performance gains.

    Any idea how I can debug the issue?

  • 9

    Deactivate purging of Tailwind base classes

    I had issues (#30) where base classes were purged so I let PurgeCSS ignore the site styling as well as the Tailwind basics.

    (First time trying pull requests. Please review and let me know if it works or if there is a simpler solution.)

  • 10

    @tailwindcss/typography classes missing after building

    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.

  • 11

    Debloat and improve tailwindcss configuration

    I've started to notice that your current configuration of purgeCSS will produce bugs on production, I've made my portfolio using this starter template and started to notice that some of the CSS classes that i've made were removed when building, which was really annoying not seeing the changes I've done in development.

    Here are the changes the I've made to fix the problem

    1. As a first point the dependency @fullhuman/postcss-purgecss is not required, tailwindcss already has it, the documentation clearly says

    PurgeCSS (the library we use under the hood)

    1. Based on the first point you could introduce these changes 2.1 Provide an array of paths to all of your template files using the purge field in tailwind.config.js
    const themeDir = __dirname + '/../../';
    
    module.exports = {
      // === Removing unused css === //
    
      // 1. Provide an array of paths to all of your template files using the purge option
      purge: [
        themeDir + 'layouts/**/*.html',
        themeDir + 'content/**/*.html',
        'layouts/**/*.html',
        'content/**/*.html',
        'exampleSite/layouts/**/*.html',
        'exampleSite/content/**/*.html',
      ],
    
      // ...
    

    2.2 Remove the purgecss config on postcss.config.js

    1. Line 36 on postcss.config.js it's unnecessary, the docs say

    Now whenever you compile your CSS with NODE_ENV set to production, Tailwind will automatically purge unused styles from your CSS.

    This can be done easily using the env bash command which will set enviroment variables, as an example

    env MODE=\"production\" NODE_ENV=\"production\" hugo
    
    1. And as a last point and most import one, to not remove css clases that someone else writes , the documentation states

    Finally, we recommend only applying PurgeCSS to Tailwind's utility classes, and not to base styles or component classes

    Which is done by adding purgeCSS ignore comment rules on assets/css/styles.css between line 1 and 6

    /* purgecss start ignore */
    /* Tailwind base - put variables under: tailwind.config.js */
    @import "node_modules/tailwindcss/base";
    /* Tailwind component classes registered by plugins*/
    @import "node_modules/tailwindcss/components";
    /* Site Specific */
    @import "assets/css/site";
    /* purgecss end ignore */
    /* Tailwind's utility classes - generated based on config file */
    @import "node_modules/tailwindcss/utilities";
    
    

    Without this, there will be removed classes

    As an example if you use gohugo's auto generated structures such as code fences which include the class .highlight and you reference this class on an external stylesheet PurgeCSS will remove it on since it does not knows about it.

    I guess then you could easily make changes to the configuration. To fix these problems.

    You have my portfolio repository as an example. Here are the changes that i've made to do the fix.

  • 12

    Doesn't change the final css: no watching

    It seems that the tailwind doesn't watch the changes...

    For example, if I add a class max-w-3xl, then it doesn't show up in the final css unless ctrl+c and re-run hugo server ...

    feel like none of the current solutions solve the problem of Tailwind and Hugo collaboration

  • 13

    Tailwind content, purgecss problems and questions

    Hey there, thanks for this great starter kit. See my repo here: https://github.com/artzte/juniper-swordplay

    Bunch of n00b questions here; pardon me. I was using an older version of your theme and am trying to update.

    The util classes aren't being detected in my setup, which I created following your directions here:

     hugo server --disableFastRender --verbose
    Start building sites … 
    hugo v0.94.2-48FB9E4D linux/amd64 BuildDate=2022-03-12T10:28:42Z VendorInfo=gohugoio
    INFO 2022/03/13 16:09:54 syncing static files to /
    INFO 2022/03/13 16:09:54 postcss: use config file /home/eric/src/juniper-swordplay/themes/juniper-swordplay/assets/css/postcss.config.js
    INFO 2022/03/13 16:09:55 postcss: 
    INFO 2022/03/13 16:09:55 postcss: warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
    INFO 2022/03/13 16:09:55 postcss: warn - https://tailwindcss.com/docs/content-configuration
    

    I'm confused by the tailwind config. The content entry is referencing relative to the local folder of the tailwind.config.js, which is not where the layouts are.

    Also, why is purgeCSS needed? Tailwind already purges, which is why the content entries in the tailwind config are so critical.

  • 14

    Jit Mode?

    Hi i try to enable Jit Mode i got this error

    Error: Error building site: POSTCSS: failed to transform "css/styles.css" (text/css): warn - You have enabled the JIT engine which is currently in preview.
    warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
    Error: ENOENT: no such file or directory, stat '/Users/uriah/Code/Hugo/new-theme/stdin'
        at Object.statSync (fs.js:1086:3)
        at trackModified (/Users/uriah/code/Hugo/new-theme/node_modules/tailwindcss/jit/lib/setupContext.js:233:26)
        at /Users/uriah/code/Hugo/new-theme/node_modules/tailwindcss/jit/lib/setupContext.js:728:38
        at /Users/uriah/code/Hugo/new-theme/node_modules/tailwindcss/jit/index.js:35:47
        at LazyResult.runOnRoot (/Users/uriah/.fnm/node-versions/v14.16.0/installation/lib/node_modules/postcss/lib/lazy-result.js:303:16)
        at LazyResult.runAsync (/Users/uriah/.fnm/node-versions/v14.16.0/installation/lib/node_modules/postcss/lib/lazy-result.js:355:26)
        at async Promise.all (index 0) {
      errno: -2,
      syscall: 'stat',
      code: 'ENOENT',
      path: '/Users/uriah/Code/Hugo/new-theme/stdin'
    }
    

    also have this with my old projects...

    I would love to know if someone already has solution on this with the postcss

    Looking forward for an answer thanks