How to mount a node_modules folder?

Hello,

I cannot figure out how to mount a node_modules package in order to have an import resolved by css.PostCSS when using Hugo 0.165.0. I use tailwindcss 3 and therefore have to stay with css.PostCSS if I understand that part correctly.

[[module.mounts]]
source = "node_modules/maplibre-gl/dist"
target = "assets/maplibre-gl"

hugo config mount looks good:

"mounts": [
{
"source": "assets",
"target": "assets"
},
{
"source": "content",
"target": "content"
},
{
"source": "node_modules/maplibre-gl/dist",
"target": "assets/css/maplibre-gl"
},

But resources.Get "maplibre-gl/maplibre-gl.css" or any resources.GetMatch does not find the file. The goal would be to provide this resource via importContext to css.PostCSS to have it resolved.

The whole ordeal currently looks like this:


{{- $styles := (slice (resources.Get "css/tailwind.css")) -}}
{{- /\* Include styles provided by modules. \*/ -}}
{{- if (reflect.IsMap .) -}}
{{- range $name, $data := .modules -}}
{{- with (index $data "css") -}}
{{ $styles = $styles | append . }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $maplibre := resources.Get "css/maplibre-gl/maplibre-gl.css" -}}
{{ warnf "CSS %s %s" $styles $maplibre }}
{{ if not $maplibre }}
{{ errorf "MAPLIBRE NOT FOUND" }}
{{ end }}
{{- $options := dict "inlineImports" true "skipInlineImportsNotFound" false -}}
{{- $styles = $styles | resources.Concat "css/main.css" | css.PostCSS $options -}}

Am I missing something or is this approach not feasible? Thanks.

OK, as its often the case, after some sleep I got it working again. Ditched the Hugo importing and fall back to the postcssImport plugin. I had to adjust the paths of the local imports to include the paths though. And that although the asset path has been provided to the plugin. Tried several variations, relative, absolute. The import plugin shows me its lookup paths, they are correct, the files are in there, but they cannot be found when the file import is not provided with a path like @import "/assets/css/fonts.css";.