60dd993a6content: Update GitHub Pages workflow6247e3590content: Fix typoa22255b0bcontent: Update version references21afec198content: Update version reference6226532c8content: Update version reference80d26621acontent: Update version referencecda7135b5content: Fix typo70c509e8acontent: Fix typo136b20310content: Change render hook example038246c2fcontent: Fix accidental removal441375fa4netlify: Hugo 0.147.94a620931ccontent: Note that config/env/cascade.xxx is not supported6d3a7587fconfig: Ignore front matter param override warnings623b48624content: Set searchable param to false for content/en/documentation.mdd1b2aad69content: Fix Codeberg deployment article5e3d849b8search: Use front matter parameter to control search indexingb4f90e39dcontent: Note that PATH segments must exclude project directorya81406e26content: Create aliases for deleted template pages7c3adc9adcontent: Change order of template typese093eb036content: Remove admonition from template types page0015e7a9bcontent: Update to align with v0.146.0 template system (phase 1)cf986240dcontent: Update templates.Defer noteab51fdcc7content: Use consistent templates.Defer examplesb4f8e492fcontent: Fix formatting62aa94addcontent: Fix typo83747f36bcontent: Update FAQsfc644d894Update netlify.toml4151f3a5bcontent: Fix typo9452bca92content: Update description ToMath strict option982b863c3content: Add instructions about deploying to root of user's Codeberg Pagesfc7cd2878theme: Generate QR code once per page784891b87content: Update links to the CommonMark specification741113fb5content: Fix incorrect link to Shortcodes tutorialc4962f1accontent: Update transform.ToMathad7b87223Update netlify.toml2d64e57aetheme: Remove bullet from new-in badge55a832f8eUpdate ToMath.mde1e624f49content: Document transform.ToMath strict mode2df6218f8netlify: Hugo 0.147.60259b88f1Revert "theme: Display date on news items from content adapter"43b35e56atheme: Adjust admonition dark mode colors2f15e9c34theme: Add link to Mastodond99e979d4theme: Display date on news items from content adapter6c93dac97content: Clarify the AddResource content value49006468econtent: Describe Codeberg's Forgejo Actionsbe80c3b82content: Update css.TailwindCSS optsb3ba4329ctheme: Update css.TailwindCSS opts and remove tailwind.config.js902e360b0content: Update stylesheet link for katex.js8b9e1ba3econtent: Update stylesheet link for katex.js7dae3b0e8content: Update TailwindCSS instructionscb093d210Update netlify.toml577d6fbb1content: Remove GitCMS for now8352af6cdUpdates for v0.147.42240f07a5content: Fix typo677b3fed3Correct openapi3.Unmarshal example580477aa5content: Fix typo0dc43b481content: Add GitCMS to commercial front ends listac4179f2bcontent: Fix relref shortcode examplesa699d267bFix typos7e28c4380Make sponsor logo responsive8e05f0425Update MaxInt64.mdf715265d3content: Document math.MaxInt640d57ff7d4Update netlify.tomld210e3476theme: Adjust sponsore73444b43content: Clarify page title valuesfd4c292b8content: Fix links to Pandocdd074dc67content: Bump version in GitHub Pages examplefe5537bb2content: Describe the pandoc format10834529etheme: Remove duplicate meta element838706d6etheme: More changes related to new template systemb0b6b1e69Update new-templatesystem-overview.mde719d2360Update new-templatesystem-overview.mdec2bbd395Update new-templatesystem-overview.md53319a681Add a one pager about the new template systeme17416c05Fix the spelling issue on the Host on Render descriptione8e1c82aacontent: Document range-over-int introduced in v0.123.0bc478f98fcontent: Fix editing errors606547b48Update netlify.tomle224f3f82content: Fix formatting24e4acc41content: Fix typo1e773f34bcontent: Fix typo5ef94a725content: Document alternative to shuffle for large collections7fe42d76ccontent: Fix sample code formatting5d601448fcontent: Update mathematical markup guidance63b4fe2c0content: Update version references722da91f1content: Fix GO_VERSION in Netlify hosting example8cc589c3atheme: Add current Hugo version to the header37aa24ac5netlify: Hugo 0.147.1a80b25e24content: Remove dated new-in89dcf0f92content: Fix path formatting1a5191d78content: Update transformation examples3327065abUpdate Text.md557c10dd2content: Miscellaneous updates for v0.147.00dae1a185netlify: Hugo 0.147.09b44821c3Merge branch 'tempv0.147.0'f1481e8c3content: Update GitLab Pages workflow example2e61a0360content: Update content format descriptionsfb42d7c2aimages: Add option for vertical alignment to images.Text git-subtree-dir: docs git-subtree-split:60dd993a65
4.0 KiB
title, description, categories, keywords, params
| title | description | categories | keywords | params | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| css.TailwindCSS | Processes the given resource with the Tailwind CSS CLI. |
|
{{< new-in 0.128.0 />}}
Use the css.TailwindCSS function to process your Tailwind CSS files. This function uses the Tailwind CSS CLI to:
- Scan your templates for Tailwind CSS utility class usage.
- Compile those utility classes into standard CSS.
- Generate an optimized CSS output file.
Note
Use this function with Tailwind CSS v4.0 and later, which require a relatively modern browser to render correctly.
Setup
Step 1
Install the Tailwind CSS CLI v4.0 or later:
npm install --save-dev tailwindcss @tailwindcss/cli
The Tailwind CSS CLI is also available as a standalone executable. You must install it outside of your project directory and ensure its path is included in your system's PATH environment variable.
Step 2
Add this to your site configuration:
{{< code-toggle file=hugo copy=true >}} [build] [build.buildStats] enable = true build.cachebusters source = 'assets/notwatching/hugo_stats.json' target = 'css' build.cachebusters source = '(postcss|tailwind).config.js' target = 'css' [module] module.mounts source = 'assets' target = 'assets' module.mounts disableWatch = true source = 'hugo_stats.json' target = 'assets/notwatching/hugo_stats.json' {{< /code-toggle >}}
Step 3
Create a CSS entry file:
@import "tailwindcss";
@source "hugo_stats.json";
Tailwind CSS respects .gitignore files. This means that if hugo_stats.json is listed in your .gitignore file, Tailwind CSS will ignore it. To make hugo_stats.json available to Tailwind CSS you must explicitly source it as shown in the example above.
Step 4
Create a partial template to process the CSS with the Tailwind CSS CLI:
{{ with resources.Get "css/main.css" }}
{{ $opts := dict "minify" (not hugo.IsDevelopment) }}
{{ with . | css.TailwindCSS $opts }}
{{ if hugo.IsDevelopment }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ else }}
{{ with . | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}
{{ end }}
{{ end }}
{{ end }}
Step 5
Call the partial template from your base template, deferring template execution until after all sites and output formats have been rendered:
<head>
...
{{ with (templates.Defer (dict "key" "global")) }}
{{ partial "css.html" . }}
{{ end }}
...
</head>
Options
- minify
- (
bool) Whether to optimize and minify the output. Default isfalse. - optimize
- (
bool) Whether to optimize the output without minifying. Default isfalse. - disableInlineImports
- {{< new-in 0.147.4 />}}
- (
bool) Whether to disable inlining of@importstatements. Inlining is performed recursively, but currently once only per file. It is not possible to import the same file in different scopes (root, media query, etc.). Note that this import routine does not care about the CSS specification, so you can have@importstatements anywhere in the file. Default isfalse. - skipInlineImportsNotFound
- (
bool) Whether to allow the build process to continue despite unresolved import statements, preserving the original import declarations. It is important to note that the inline importer does not process URL-based imports or those with media queries, and these will remain unaltered even when this option is disabled. Default isfalse.