- Hugo and Tailwind CSS Project Setup
Here's a comprehensive README.md document that compiles all the instructions on how to set up a Hugo project, including how to add a custom theme and integrate Tailwind CSS:
This guide provides detailed instructions on how to set up a Hugo static site with Tailwind CSS integrated, directly within an existing project directory.
Before you start, you need to have Hugo and Node.js (with npm) installed on your system.
- Hugo: Installation Guide
- Node.js and npm: Download Page
Navigate to your project directory and initialize a new Hugo site. This command will also force Hugo to create a new site even if files are already present in the directory.
hugo new site . --force
Congratulations! Your new Hugo site is now created in your current project directory.
-
Create a custom theme:
hugo new theme <THEMENAME>
Replace
<THEMENAME>
with your desired theme name. -
Install a theme from Hugo themes gallery: Hugo Themes
Set the theme in the config.toml
file:
theme = "<THEMENAME>"
Create new content by specifying the section and filename:
hugo new content/<SECTIONNAME>/<FILENAME>.<FORMAT>
Install Tailwind CSS and its peer dependencies:
npm install tailwindcss@latest postcss@latest autoprefixer@latest
Generate the Tailwind and PostCSS configuration files:
npx tailwindcss init -p
Configure PurgeCSS in tailwind.config.js
to remove unused styles:
module.exports = {
purge: ['./layouts/**/*.html', './content/**/*.md'],
theme: {
extend: {},
},
plugins: [],
}
Create a CSS file at assets/css/styles.css
and include Tailwind's directives:
@tailwind base;
@tailwind components;
@tailwind utilities;
Update package.json
to add scripts for building CSS:
"scripts": {
"build:css": "postcss assets/css/styles.css -o static/css/styles.css",
"watch:css": "postcss assets/css/styles.css -o static/css/styles.css --watch"
}
Build the CSS:
npm run build:css
Automatically rebuild CSS on changes:
npm run watch:css
Include the compiled CSS in your layouts:
<link rel="stylesheet" href="{{ .Site.BaseURL }}css/styles.css">
Serve your site locally with Hugo's built-in server, which supports live reloading:
hugo server --buildDrafts
Build your site to generate the static files:
hugo
You now have a Hugo site integrated with Tailwind CSS ready for development. For more information on customization and advanced configurations, refer to the Hugo documentation and the Tailwind CSS documentation.
This README.md document serves as a complete guide to setting up a Hugo project with Tailwind CSS, tailored for rapid development and easy deployment. It covers every step from initial setup to development and build processes.