mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
9cabb46f68
d1157b687 Fix typo -- missing word in title 34c9a9ff3 Remove Hartwell Insurance subpage broken link d42f6d8eb Fix strings.Repeat documentation 09b49debb Release 0.76.5 149877735 Merge branch 'tempv0.76.5' 72ffeb026 releaser: Add release notes to /docs for release of 0.76.5 4150d8ae8 Fixed typo: update PrevPage to Prev c3e630db1 Update index.md deb7520a8 Release 0.76.4 f58bd7134 Merge branch 'tempv0.76.4' 2581fe4bc releaser: Add release notes to /docs for release of 0.76.4 26d8417fc Release 0.76.3 34c49e06a Merge branch 'tempv0.76.3' 0de2af2ef releaser: Add release notes to /docs for release of 0.76.3 cce12c0f7 Add missing closing quotes and fix code-block lang (#1250) 8c1c80d9f Update AMP link (#1251) 7b1211ffa Fix typos in multilingual.md 29e9d70fd Update index.md 172a5480b Release 0.76.2 93ff424d3 Merge branch 'temp762' 3cad3c23a releaser: Add release notes to /docs for release of 0.76.2 610221964 Update index.md 8a9d31709 Release 0.76.1 64b245aa4 Merge branch 'temp761' f19469ff8 releaser: Add release notes to /docs for release of 0.76.1 97f0ed030 Update front-matter.md cca71f263 Update index.md 23c64f6a3 Fix typo in 0.76.0 release note 5f79e034d Update index.md b66567de2 netlify: Bump to Hugo 0.76.0 a3e30300d Release 0.76.0 3b057e8fe releaser: Add release notes to /docs for release of 0.76.0 7fa1cd912 docs: Regen docshelper 769712aec Merge commit 'e5568488051a571df48401e03f1304b95dbc9028' 70ce6ae33 pagemeta: Make BuildConfig.Render an enum a78d3849f Allow cascade to be a slice with a _target discriminator 705fea656 Add force flag to server redirects config 04e4e1cc1 tpl: Add Do Not Track (dnt) option to Vimeo shortcode 025c19fe1 Fix CLI example for PostCSS 8 0c70c47b2 markup/asciidocext: Add preserveTOC option git-subtree-dir: docs git-subtree-split: d1157b687e25054501c3bcbb735da51229f66b74
81 lines
2.4 KiB
Markdown
Executable file
81 lines
2.4 KiB
Markdown
Executable file
---
|
|
title: PostCSS
|
|
description: Hugo Pipes can process CSS files with PostCSS.
|
|
date: 2018-07-14
|
|
publishdate: 2018-07-14
|
|
lastmod: 2018-07-14
|
|
categories: [asset management]
|
|
keywords: []
|
|
menu:
|
|
docs:
|
|
parent: "pipes"
|
|
weight: 40
|
|
weight: 40
|
|
sections_weight: 40
|
|
draft: false
|
|
---
|
|
|
|
|
|
Any asset file can be processed using `resources.PostCSS` which takes for argument the resource object and a slice of options listed below.
|
|
|
|
The resource will be processed using the project's or theme's own `postcss.config.js` or any file set with the `config` option.
|
|
|
|
|
|
```go-html-template
|
|
{{ $css := resources.Get "css/main.css" }}
|
|
{{ $style := $css | resources.PostCSS }}
|
|
```
|
|
|
|
{{% note %}}
|
|
Hugo Pipe's PostCSS requires the `postcss-cli` JavaScript package to be installed in the environment (`npm install -g postcss postcss-cli`) along with any PostCSS plugin(s) used (e.g., `npm install -g autoprefixer`).
|
|
|
|
If you are using the Hugo Snap package, PostCSS and plugin(s) need to be installed locally within your Hugo site directory, e.g., `npm install postcss-cli` without the `-g` flag.
|
|
{{% /note %}}
|
|
### Options
|
|
|
|
config [string]
|
|
: Path to the PostCSS configuration file
|
|
|
|
noMap [bool]
|
|
: Default is `true`. Disable the default inline sourcemaps
|
|
|
|
inlineImports [bool] {{< new-in "0.66.0" >}}
|
|
: Default is `false`. 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.
|
|
|
|
_If no configuration file is used:_
|
|
|
|
use [string]
|
|
: List of PostCSS plugins to use
|
|
|
|
parser [string]
|
|
: Custom PostCSS parser
|
|
|
|
stringifier [string]
|
|
: Custom PostCSS stringifier
|
|
|
|
syntax [string]
|
|
: Custom postcss syntax
|
|
|
|
```go-html-template
|
|
{{ $style := resources.Get "css/main.css" | resources.PostCSS (dict "config" "customPostCSS.js" "noMap" true) }}
|
|
```
|
|
|
|
## Check Hugo Environment from postcss.config.js
|
|
|
|
{{< new-in "0.66.0" >}}
|
|
|
|
The current Hugo environment name (set by `--environment` or in config or OS environment) is available in the Node context, which allows constructs like this:
|
|
|
|
```js
|
|
module.exports = {
|
|
plugins: [
|
|
require('autoprefixer'),
|
|
...process.env.HUGO_ENVIRONMENT === 'production'
|
|
? [purgecss]
|
|
: []
|
|
]
|
|
}
|
|
```
|