Storing postcss-cli and other packages under theme directory?

I’m developing a theme using postcss, tailwind and a few other bits. This requires me to use npm to install the various required packages, which is fine. But, my problem is this only seems to work if you run npm i postcss-cli from the root directory for the hugo site. I also have to place my postcss.config.js file within the root directory.

I’m not comfortable doing this as such packages have nothing to do with hugo and more to do with the theme. If I want to upload my theme to github to share with others the user would have to manually install the npm packages within their root hugo directory.

I think a better solution would be allow the user to provide a path to the configuration, or default to root directory.

That way I can upload the theme along with the package.json and postcss.config.js and the user can just run npm install from within that directory and everything will be setup fine.

Maybe this is already possible. But I can’t seem to find anything in the documentation.

Basically what I want to do is store the package.json, node_modules, postcss.config.js etc under /hugo-website/themes/my-custome/theme/node_modules … rather than /hugo-website/node_modules.


I can sort of get it to work by providing a custom path to the postcss.config.js file like so:

<style>{{ ( resources.Get "css/base.css" | resources.PostCSS (dict "config" "themes/my-theme/postcss.config.js" "noMap" true) ).Content | safeCSS }}</style>

The problem is it doesn’t pick up autoprefixer which is installed at the same location as the postcss.config.js:


Everything is working when I use the root directory. But, I don’t feel that’s the place for theme related resources. Sharing the theme is an example of where this breaks.