I’m working on migrating as much of my Gulp based workflow onto Hugo pipes. To that end I’m converting my existing code to a new base theme (codes on github ).
I’m adding the main.css like so:
{{ $postcssed := resources.Get "css/main.css" | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $postcssed.Permalink }}">
Which pulls the stylesheet in from assets and processes it. The problem is I like using postcss-import to keep css modular and postcss-import doesn’t seem to know where to look for imported stylesheets when run via hugo pipes.
Building sites … Error: Failed to find 'normalize.css'
in [/home/adrian/Admin/hugoBasicExample]
at resolveModule.catch.catch (/home/adrian/Admin/hugoBasicExample/themes/Pippy/node_modules/postcss-import/lib/resolve-id.js:35:13)
The import occurs at the start of main.css like so:
@import 'normalize.css';
@import 'vars.css';
It works if postcss-import is run via gulp or on the cli with postcss-cli like:
postcss "assets/css/main.css" --verbose -o "main-post.css"
postcss-import will search in the directory of the file passed to it by default and the imported stylesheets are sitting right there. So it seems that hugo postCSS is losing the context along the way, or at least not passing it on to postcss.
The postcss-cli docs describe using a function to pass context in postcss.config.js see here but trying that results in this error:
Building sites … TypeError: Cannot read property 'dirname' of undefined
at module.exports.ctx (/home/adrian/Admin/hugoBasicExample/themes/Pippy/postcss.config.js:4:40)
at config.load.then (/home/adrian/.npm-global/lib/node_modules/postcss-cli/node_modules/postcss-load-config/src/index.js:62:18)
So it would seem that hugo postCSS isn’t passing or setting the context for that to work.
The only workaround I’ve found so far is to specify the @import with the full root filesystem path to the imported stylesheets. Not very portable.
So is there some feature I’m missing or is this pointing to an underlying bug/missing feature in hugo’s postCSS inclusion?