I am trying to find out how I could use postcss-uncss together with hugo.
With the setup
{{ $style := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "style.scss" . | toCSS (dict "targetPath" "css/style.css" "enableSourceMap" false) | resources.PostCSS (dict "use" "postcss-uncss") }}
I get the error Building sites … Error: UnCSS: no HTML files found
which kind of make sense, as the plugin expects a html and not css.
So how can I apply the plugin on the HTML contnent within hugo or is it needed to use a cli for that?
You probably need to pass the correct options in the postcss config file
Vad1mo
3
I couldn’t find a solution so for now I am doing it outside of hugo
uncss() {
command -v uncss >/dev/null 2>&1 || { echo >&2 "uncss is required. Trying to install."; npm i -g uncss; }
find public/ -name "*.html" -exec uncss -n -H public/ -C public/css/ {} -o public/css/style.min.*.css +
ls -lah public/css/
}
Took me some time but this is the final solution
find public/ -name "*.html" -exec uncss -H public/ -C public/css/ '{}' -o public/css/style.min.*.css +
Simpler Version, works with for bash and globestar enabled:
uncss -H public/ -C public/css/ public/**/*.html -o public/css/style.min.*.css +