PostCSS

The PostCSS config and PurgeCSS setup of hugolify-theme-bootstrap, provided by the module

Nothing to create in your project

The module ships its own PostCSS config and points Hugo at it. Your project installs the npm packages that config needs, and enables the build stats.

Bootstrap generates a large stylesheet, so this config is also where PurgeCSS removes the classes your site never renders.

Requires hugolify-theme-bootstrap v1.36.0 or later. Older releases expected a copy in postcss/bootstrap/, see Troubleshooting.

How it is loaded

Hugo mounts the postcss.config.* files found at the root of each module, and of your project, into assets/_jsconfig. The module declares its own in its hugo.yaml, so there is nothing to declare in your project params:

# provided by hugolify-theme-bootstrap, do not repeat it
params:
  css:
    postcss: "postcss.config.cjs"
postcss.config.cjs in the module

It runs two plugins: autoprefixer, driven by the .browserslistrc of your project (the browserslist defaults without one), and @fullhuman/postcss-purgecss.

Enable the build stats

PurgeCSS does not read the rendered HTML. It reads hugo_stats.json, the list of tags, classes and ids Hugo actually emitted. That file has to be enabled:

/config/_default/hugo.yaml

build:
  buildStats:
    disableClasses: false
    disableIDs: true
    disableTags: false
    enable: true

build.writeStats: true is the deprecated form of the same switch. Use build.buildStats.enable: it lets you keep ids out of the file, which keeps it small.

The safelist

A class that only ever appears at runtime (added by JavaScript, or built by string concatenation) is invisible to Hugo, so it never lands in hugo_stats.json and PurgeCSS strips it. The safelist puts it back.

EntryWhy
show, showing, hide, fadeBootstrap toggles them from JS (collapse, modal, offcanvas)
/-backdrop$/Backdrops are injected by Bootstrap at runtime
/^is-/State classes set by the Hugolify vanilla JS
/^splide_/, /^tobii/Class names generated by the carousel and lightbox vendors

When a component of yours toggles a class from JavaScript, add it to the safelist of your own config, see Override the config.

Install the packages

hugo mod get && hugo mod npm pack && yarn install

Projects started from hugolify-template have it as a script:

yarn install:hugolify

Run it again after every hugo mod get -u: the npm dependencies are declared by the modules, and hugo mod npm pack is what copies them into your package.json.

Override the config

Copy the module’s file to the root of your project, as postcss.config.cjs: Hugo mounts it at the same place as the module’s, and the files of your project come first. Then add your safelist entries.

Keep that exact name, it is the one the module points at. The .cjs extension makes it CommonJS: write it with require(), like the module’s.

Why CommonJS: Node loads the module’s file from the Hugo module cache, which has no node_modules. The plugins come from the node_modules of your project, that Hugo passes as NODE_PATH. require() reads it on every Hugo version, an ESM import ignores it before Hugo 0.164.

Troubleshooting

The build fails, or hangs, on the CSS

Check your Node.js version. Since Hugo 0.161, Node runs with the permission model, and older releases crash while resolving the config (Access to this API has been restricted) or never return. Use Node 24.5 or later, or 22.20 or later on Node 22.

On Netlify, set the version in netlify.toml:

[build.environment]
  NODE_VERSION = "24"

postcss config “postcss/bootstrap” not found

POSTCSS: failed to transform "sass/main.sass" (text/css):
postcss config "postcss/bootstrap" not found

The module is older than v1.36.0 and still looks for a copy in your project. Update it:

hugo mod get -u github.com/hugolify/hugolify-theme-bootstrap && yarn install:hugolify

Then delete what the project no longer needs: the postcss/bootstrap/ directory and a postcss.config.js left at the root. If your copy had safelist entries of your own, move them to an override first.

Cannot find module

Error: Cannot find module '@fullhuman/postcss-purgecss'

The npm packages are not installed: run the install command.

Styles missing in production only

PurgeCSS runs on every build, but a class rendered on a page you did not build locally is absent from hugo_stats.json. Build the whole site once (yarn build) before judging what was purged.

Documentation