From 99713d44bb9d7076237c503fc0ebe605769381ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 26 Feb 2020 10:06:04 +0100 Subject: [PATCH] resources: Add basic @import support to resources.PostCSS This commit also makes the HUGO_ENVIRONMENT environment variable available to Node. Fixes #6957 Fixes #6961 --- content/en/hugo-pipes/postcss.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/content/en/hugo-pipes/postcss.md b/content/en/hugo-pipes/postcss.md index a0a673798..a7ba097fa 100755 --- a/content/en/hugo-pipes/postcss.md +++ b/content/en/hugo-pipes/postcss.md @@ -39,6 +39,12 @@ config [string] 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] @@ -55,4 +61,21 @@ syntax [string] ```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] + : [] + ] +} ``` \ No newline at end of file