mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Merge commit '07b8d9466dfb59c429c1b470a0443337bc0aeefe'
This commit is contained in:
@@ -35,10 +35,12 @@ There are several ways to set up CSS purging with PostCSS in Hugo. If you have a
|
||||
|
||||
The below configuration will write a `hugo_stats.json` file to the project root as part of the build. If you're only using this for the production build, you should consider placing it below [config/production](/getting-started/configuration/#configuration-directory).
|
||||
|
||||
```toml
|
||||
{{< code-toggle file="config" >}}
|
||||
[build]
|
||||
writeStats = true
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
`postcss.config.js`
|
||||
|
||||
```js
|
||||
const purgecss = require('@fullhuman/postcss-purgecss')({
|
||||
@@ -50,12 +52,10 @@ const purgecss = require('@fullhuman/postcss-purgecss')({
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
require('tailwindcss'),
|
||||
require('autoprefixer'),
|
||||
...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : [])
|
||||
]
|
||||
};
|
||||
plugins: [
|
||||
...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : [])
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
Note that in the example above, the "CSS purge step" will only be applied to the production build. This means that you need to do something like this in your head template to build and include your CSS:
|
||||
|
@@ -18,7 +18,7 @@ draft: false
|
||||
|
||||
In order to use Hugo Pipes function on an asset file containing Go Template magic the function `resources.ExecuteAsTemplate` must be used.
|
||||
|
||||
The function takes three arguments, the resource object, the resource target path and the template context.
|
||||
The function takes three arguments: the resource target path, the template context, and the resource object.
|
||||
|
||||
```go-html-template
|
||||
// assets/sass/template.scss
|
||||
@@ -35,4 +35,4 @@ body{
|
||||
```go-html-template
|
||||
{{ $sassTemplate := resources.Get "sass/template.scss" }}
|
||||
{{ $style := $sassTemplate | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS }}
|
||||
```
|
||||
```
|
||||
|
Reference in New Issue
Block a user