mirror of
https://github.com/gohugoio/hugo.git
synced 2026-09-03 20:22:38 +00:00
bfa7453792
71f739460content: Reformat procedures to use description lists instead of H3 elements420a78802content: Remove 21YunBox hosting guideabeea342fcontent: Add hosting guide for Vercel3aaca6c0acontent: Add hosting guide for Renderd77b06aa6content: Fix formatting82885415fcontent: Change build.sh file perms in Cloudflare hosting docs0569c68cacontent: Fix typo8f14be5dacontent: Remove duplicate list itemse76f17815misc: Fix typo in configuration for the Markdown linter32e450b7cmisc: Fix typo in configuration for the Markdown linter81bd0056amics: Update configuration for the Markdown linter480ae9014content: Improve file names in the PageInner descriptionb17999021content: Adjust Markdown to pass linter tests1d9d56897misc: Implement Markdown linter91fc34c58content: Miscellaneous editsb7c60ae0bcontent: Add admonition for outdated learning resources51b6df588misc: Activate stale action84a897f5fmisc: Implement stale action167ea9713content: Update GitHub Pages workflow example3672d9116misc: Use actions/checkout@v5 in workflows2f2b4c968misc: Update spellcheck configs55a8ff7aecontent: Fix typo36e3d7b7bAdjust sponsors51014e6b9content: Fix link37cfc093fcontent: Add Cloudflare Worker hosting instructions09862ffadcontent: Update hosting considerations related to GitInfo477f3e7c0misc: Update cspell config7a7bb4874content: Miscellaneous edits48486d5accontent: Remove Cloudflare Pages documentation382f8052dcontent: Remove KeyCDN documentation8ecbc985ccontent: Update hosting workflow files57fd362bfcontent: Clarify applicability of the slug front matter field0dcfff9c7content: Update directory-structure.md58e3609a0content: Fix typo22fb43695content: Fix search/replace errorsfba8342a8content: Fix missing link refs97e035006Update netlify.toml6ab5ae6dfcontent: Improve GitLab Pages compression performance172bfbc4bcontent: Differentiate content view templates from other templates978770fc8content: Clarify handling of goldmark extensions conflictcb74aa4c7content: Improve Codeberg Pages hosting instructions794477792content: Add custom domain instructions to Codeberg Pages setup235fac27dcontent: Improve description of code block render hook options map35a507d31content: Improve WP2Hugo description8191f4dcfcontent: Improve WP2Hugo description25cca30fdcontent: Fix typee955652aecontent: Improve base template description922aa91bdcontent: Improve description of partial lookup logic072536ef6content: Update template type documentation5bf153531Update netlify.tomlcdd20a433content: Indicate language sort order for relevant page methodsfc9a868c9content: Add Sitepins to list of commercial CMS platformsb6077449ccontent: Update version referencesb71388caccontent: Fix typoc27dfdef3content: Move link referenced008ea6accontent: Fix typo040f14a3ccontent: Fix typo1ac119d26content: Fix typoa5a4fa907content: More updates for v0.148.0b7247a8eacontent: Remove command chaining from GitHub Actions workflow6ecb96bcdcontent: Updates for v0.148.0aea9e4c29netlify: Update Hugo version4e71546d1Add Ancestors (plural) method to GitInfo, rename Ancestor field to Parent68620a6c2source: Expose Ancestor in GitInfo git-subtree-dir: docs git-subtree-split:71f739460f
3.8 KiB
3.8 KiB
title, description, categories, keywords, params
| title | description | categories | keywords | params | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| css.PostCSS | Processes the given resource with PostCSS using any PostCSS plugin. |
|
{{< new-in 0.128.0 />}}
{{ with resources.Get "css/main.css" | postCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
Setup
Follow the steps below to transform CSS using any of the available PostCSS plugins.
- Step 1
- Install Node.js.
- Step 2
- Install the required Node.js packages in the root of your project. For example, to add vendor prefixes to your CSS rules:
npm i -D postcss postcss-cli autoprefixer - Step 3
- Create a PostCSS configuration file in the root of your project.
module.exports = { plugins: [ require('autoprefixer') ] };Note
If you are a Windows user, and the path to your project contains a space, you must place the PostCSS configuration within the package.json file. See this example and issue #7333.
- Step 4
- Place your CSS file within the
assets/cssdirectory. - Step 5
- Process the resource with PostCSS:
{{ with resources.Get "css/main.css" | postCSS }} <link rel="stylesheet" href="{{ .RelPermalink }}"> {{ end }}
Options
The css.PostCSS method takes an optional map of options.
- config
- (
string) The directory that contains the PostCSS configuration file. Default is the root of the project directory. - noMap
- (
bool) Whether to disable inline source maps. Default isfalse. - inlineImports
- (
bool) Whether to enable inlining of import statements. It does so recursively, but will only import a file once. URL imports (e.g.@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');) and imports with media queries will be ignored. Note that this import routine does not care about the CSS spec, so you can have @import anywhere in the file. Hugo will look for imports relative to the module mount and will respect theme overrides. Default isfalse. - skipInlineImportsNotFound
- (
bool) Whether to allow the build process to continue despite unresolved import statements, preserving the original import declarations. If you have regular CSS imports in your CSS that you want to preserve, you can either use imports with URL or media queries (Hugo does not try to resolve those) or set this option totrue. Default isfalse."
{{ $opts := dict "config" "config-directory" "noMap" true }}
{{ with resources.Get "css/main.css" | postCSS $opts }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
No configuration file
To avoid using a PostCSS configuration file, you can specify a minimal configuration using the options map.
- use
- (
string) A space-delimited list of PostCSS plugins to use. - parser
- (
string) A custom PostCSS parser. - stringifier
- (
string) A custom PostCSS stringifier. - syntax
- (
string) Custom postcss syntax.
{{ $opts := dict "use" "autoprefixer postcss-color-alpha" }}
{{ with resources.Get "css/main.css" | postCSS $opts }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
Check environment
The current Hugo environment name (set by --environment or in configuration or OS environment) is available in the Node context, which allows constructs like this:
const autoprefixer = require('autoprefixer');
module.exports = {
plugins: [
process.env.HUGO_ENVIRONMENT !== 'development' ? autoprefixer : null
]
}