I don't get my head around about (hu)go-modules - A few questions regarding mounts

So I have the following structure:

hugo-site:
  content-dir
  config
  archetype
  themes
      my-hugo-theme

site config for mounts:

mounts:
  - source: content
    target: content

  # - source: node_modules
  #   target: assets
  - source: assets
    target: assets

  - source: static
    target: static

....
theme: 
  - my-hugo-theme

in my-hugo-theme

i have:

  layouts
  images
  exampleSite
  config
  package.json
  node_modules
  assets
  theme.yaml

theme.yaml is at the moment only placeholders:

name : 'Theme name'
license : 'MIT'
licenselink : 'https://github.com/owner/repo/LICENSE'
description : 'Theme description'

# The home page of the theme, where the source can be found
homepage : 'https://github.com/owner/repo'

# If you have a running demo of the theme
demosite : 'https://owner.github.io/repo'

# Taxonomy terms
tags : ['blog', 'company']
features : ['some', 'awesome', 'features']

# If the theme has a single author
author:
  name:  'Your name'
  homepage:  'Your website'

the config is:

module:
  mounts:
    - source: node_modules
      target: assets/vendor

so far.

I know how to mount the files, at least in theory BUT here is the thing.

I don’t really understand if I can use hugo-modules-mounts without using and initializing(?)
my theme as a module e.g. hugo mod init github.com/<your_user>/<your_project>

i only used:
hugo new theme my-hugo-theme --config "config.yaml"

My Problem and question

I want to mount the node_modules folder to the assets folder like in the docs.
But I cant really see that it worked. Neither the public build has the node_modules folder in it, or I can use the modules in my js files.

My idea was just using symlinks, but then I saw that the support was dropped a while a go.

So how do I do it ?
And are there any commands that give me some more information than hugo config mounts ?
Cause that command shows the mount of the theme.

What I want to achieve:
I want to use node_modules in my theme and give that then as a “theme” then to the main site.

So, can a theme use mounts and does hugo know of them when I am using them in a layout file ?

I still get errors and searched 3 hours to get my head around hugo modules but I just don’t get that work.


So thank you for your patience, and my tldr is:

  • can a theme use mounts and does hugo know of them when I am using them in a layout file ?
  • And are there any commands that give me some more information than hugo config mounts ?
  • How do I mount the node_modules folder ?
  • Do i need to do any more setup commands or config changes, that theme-mounts are possible ?

Best Regards and many thanks in advance,
Blackeye

I found my solution.

The issue was (I think?) a bug in hugo.

The config file was found via hugo config and the mounts also via hugo config mounts
BUT
the configs werent tracked from the “configs” folder in the theme. So my mount definition just wasnt executed.

So there were two solutions:

  1. Use a themefolder-level config file without separation e.g. config.yaml
  2. Use (following that thread ) _merge: shallow or deep. This must be done on site level of configuration e.g. hugo-site/config/config.yaml

BUT I could not use the separation of the configuration files like on site-level

config
 _default
--------config.yaml
--------params.yaml
--------module.yaml

this was not possible on theme level.
So is this a bug ?

Steps to reproduce:

  1. create a theme
  2. create config folder for theme
  3. put configs in config.yaml and params.yaml
  4. use this debug helper or do your own
{{ define "main }}
<pre>
  {{ debug.Dump .Site.Params }}
</pre>
{{ end }}

Look at the params and if the ones in from the theme are available as well.

Hope this helps :slight_smile:

TLDR Solution (for the problem, not directly the questions)

  • make sure that your config.yaml file is placed on theme-level and not in a config-folder

Hugo Version

hugo v0.140.2-aae02ca612a02e085c08366a9c9279f4abb39d94+extended linux/amd64 BuildDate=2024-12-30T15:01:53Z VendorInfo=gohugoio

I am unable to reproduce your problems:

git clone --single-branch -b hugo-forum-topic-53079 https://github.com/jmooring/hugo-testing hugo-forum-topic-53079
cd hugo-forum-topic-53079
hugo server

Works great.

very strange, it works for me as well.
I also put the config split and it works oO

Well… I refactor that theme anyway so it’s good to know that the basic structure has no flaws and that you can’t reproduce it.

Thanks! :slight_smile:
If I have any issues and can reproduce it with your example I let you know

Have a good Day

okay i refactored my theme and now everything works. There were several “dirty” structures…

like tmp folders in themes/ with old cold and configs and some old legacy code

now everything works also in my theme :slight_smile: Thanks again

Sidenote:
Go and especially Go-Template language is not really intuitive for me and I think I tried to many things out in parallel…

This can be closed, and the solution was clean up and refactor the theme to the current standards :slight_smile:

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