diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-12-22 09:43:53 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-12-22 12:43:50 +0100 |
commit | 59af05cabc74e381afb62e624afa5542a9ae8d68 (patch) | |
tree | 444fb9c276172731a5cb8f6de52adaf21bafc21b /docs/content/en | |
parent | 4989da653d601dcb539338f7e12ae825ce4a0db9 (diff) | |
download | hugo-59af05cabc74e381afb62e624afa5542a9ae8d68.tar.gz hugo-59af05cabc74e381afb62e624afa5542a9ae8d68.zip |
Add HUGO_PUBLISHDIR to the Node environment
So you can do `process.env.HUGO_PUBLISHDIR` in your `postcss.config.js` to figure out where Hugo publishes
its files.
Note that the value will always be an absolute file path and will point to a directory on disk even when running `hugo server` in memory mode.
If you write to this folder from PostCSS when running the server, you could run the server with one of these flags:
```
hugo server --renderToDisk
hugo server --renderStaticToDisk
```
Fixes #10554
Diffstat (limited to 'docs/content/en')
-rwxr-xr-x | docs/content/en/hugo-pipes/postprocess.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/content/en/hugo-pipes/postprocess.md b/docs/content/en/hugo-pipes/postprocess.md index 1aa398356..55552d105 100755 --- a/docs/content/en/hugo-pipes/postprocess.md +++ b/docs/content/en/hugo-pipes/postprocess.md @@ -68,3 +68,30 @@ Note that in the example above, the "CSS purge step" will only be applied to the {{ end }} <link href="{{ $css.RelPermalink }}" rel="stylesheet" /> ``` + + +## Hugo Environment variables available in PostCSS + +These are the environment variables Hugo passes down to PostCSS (and Babel), which allows you do do `process.env.HUGO_ENVIRONMENT === 'production' ? [autoprefixer] : []` and similar: + +PWD +: The absolute path to the project working directory. +HUGO_ENVIRONMENT (and the alias HUGO_ENV) +: The value e.g. set with `hugo -e production` (defaults to `production` for `hugo` and `development` for `hugo server`). + +HUGO_PUBLISHDIR +: {{ new-in "0.109.0" }} The absolute path to the publish directory (the `public` directory). Note that the value will always point to a directory on disk even when running `hugo server` in memory mode. If you write to this folder from PostCSS when running the server, you could run the server with one of these flags: + +``` +hugo server --renderToDisk +hugo server --renderStaticToDisk +``` + +Also, Hugo will add environment variables for all files mounted below `assets/_jsconfig`. A default mount will be set up with files in the project root matching this regexp: `(babel|postcss|tailwind)\.config\.js`. + +These will get environment variables named on the form `HUGO_FILE_:filename:` where `:filename:` is all upper case with periods replaced with underscore. This allows you do do this and similar: + +```js +let tailwindConfig = process.env.HUGO_FILE_TAILWIND_CONFIG_JS || './tailwind.config.js'; +``` + |