HUGO

PurgeCSS on file from theme's static file directory

Hello,

There is a CSS file in my theme’s static file directory, I want to run PostCSS on it (to purge it). I’m using resources.Get but that didn’t work (I get some nil reference error). I read in the docs that anything that needs to be processed by Hugo pipes should live in an assertDir.

I didn’t want to copy files from the theme folder, and since I don’t have any other assets, I configured my assertDir = "static", but that didn’t change anything about the error.

How do I go about doing this?

I updated my assetDir to themes/that-theme/static. this way it works.

I still have an issue with my PostCSS configuration. I installed postcss-cli as a global npm package, and I did the same for @fullhuman/postcss-purgecss. I get an error saying that the latter cannot be found.

Mounts are more flexible. In config.toml:

[[module.mounts]]
source = "assets"
target = "assets"

[[module.mounts]]
source = "themes/that-theme/static"
target = "assets"

See https://gohugo.io/hugo-modules/configuration/#module-config-mounts/

Please post the results of npm ls -g.

1 Like

That mounts feature is very helpful, thanks.

I managed to fix the PostCSS error by installing this npm package locally in my project. I guess it wasn’t meant to be used with a globally installed purgecss.

Just out of curiousity:

  1. Are you running Hugo as a snap?
  2. Did you install both postcss and postcss-cli?

I’m not sure what you mean by ‘snap’, I’m on Windows and I have Hugo as a standalone executable.
I installed both yes, first as global npm packages, then local to my project folder.

I hope you don’t mind me asking one more question about purgecss. My theme has some javascript file with some inline HTML with CSS classes. How do I get purgecss to analyze that inline HTML?

Right now it looks like a few CSS classes too many are being purged, so I guess it’s related to that js file.

One more question for you: does the absolute path to your project have a space anywhere. For example:

C:\Users\John Doe\etc

No clue. Probably a question for the purgecss crew.

1 Like

It does have a space yes

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.