Skip to content

Instantly share code, notes, and snippets.

@jorritfolmer
Last active November 29, 2023 06:59
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jorritfolmer/1987cd125ec4072f3c454a5b8ab2e345 to your computer and use it in GitHub Desktop.
Save jorritfolmer/1987cd125ec4072f3c454a5b8ab2e345 to your computer and use it in GitHub Desktop.
Pelican with Tailwind CSS

How to use Tailwind CSS with Pelican

These steps show how to install Tailwind CSS in a Pelican project, purge and minify it so you don't have to reference a 3+ MB CSS file but only several kB.

  1. virtualenv venv

  2. . venv/bin/activate

  3. pip install nodeenv

  4. nodeenv env

  5. . env/bin/activate

  6. npm install postcss postcss-cli autoprefixer tailwindcss purgecss cssnano

  7. npm init -y

  8. npx tailwindcss-cli@latest build -o css/tailwind.css

  9. Create postcss.config.js:

    module.exports = {
      plugins: [
        require("tailwindcss"),
        require("autoprefixer"),
        require("cssnano")
      ],
    };
    
  10. Create tailwind.config.js referencing your theme's HTML files:

    module.exports = {
      purge: [
        './themes/mynewtheme/templates/*.html',
      ],
      darkMode: false, // or 'media' or 'class'
      theme: {
        extend: {},
      },
      variants: {
        extend: {},
      },
      plugins: [],
    }
    
  11. Update package.json and replace "main" and "scripts" with:

    "main": "postcss.config.js",
    "scripts": {
      "build": "postcss css/tailwind.css -o output/static/css/tailwind.purged.min.css" 
    },
    
  12. pip install pelican[markdown]

  13. pip install pelican-seo

  14. pelican-quickstart

  15. Put a theme in ./themes/mynewtheme/ and set THEME = themes/mynewtheme in pelicanconf.py

  16. Create content

  17. make html or make publish (generate non-production or production version of the site)

  18. NODE_ENV=production npm run build (generate a minified and purged tailwind.purged.min.css)

@creativar
Copy link

Hi, Thanks for this super useful gist. Small thing... On step 10 you have tailwind.conf.js which I believe should be tailwind.config.js
:)

@jorritfolmer
Copy link
Author

Thanks! Fixed!

@lcfd
Copy link

lcfd commented Jul 13, 2022

I have created a plugin that should make your life easier.
Let me know if you have some feedback 😉

https://github.com/pelican-plugins/tailwindcss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment