HUGO

Can Hugo copy files from one dir to another?

Within a project, can Hugo copy files from one directory to another on build? For instance:

.
├── apps
│   └── library
│       └── fonts
├── static
│   └── fonts

I’d like to copy everything in apps/library/fonts to static/fonts. Possible with Hugo, on build? I’m currently manually running a Gulp task to do this, and would like to eliminate Gulp.

Yes. You can mount it inside /static. See the docs.

I have tried

[module]
  [[module.mounts]]
    source = "apps/library/fonts"
    target = "static/fonts"

in my config.toml to no avail. I have not used modules but also tried hugo mod init my-project. However it is still not mounting/copying them.

Edit: And in fact adding those lines to my config breaks my site… it seems to not be able to find anything in static/ with that present.

So (and I admit this may be surprising behaviour, but the idea behind it was noble). The mount section was intented to replace all the different staticDir, contentDir, layoutDir etc. settings, but I kept them working for legacy reasons.

But it does say in the docs that if you add a module.mounts config section, you need to configure all the mounts you use (even the defaults):

[module]

  [[module.mounts]]


    source = "apps/library/fonts"
    target = "static/fonts"

 [[module.mounts]]
    source = "content"
    target = "content"

  [[module.mounts]]
    source = "static"
    target = "static"

  [[module.mounts]]
    source = "layouts"
    target = "layouts"

  [[module.mounts]]
    source = "data"
    target = "data"

  [[module.mounts]]
    source = "assets"
    target = "assets"

  [[module.mounts]]
    source = "i18n"
    target = "i18n"

  [[module.mounts]]
    source = "archetypes"
    target = "archetypes"

Remove the one you don’t use …

1 Like

And I can add that I do variations of the above all the time, so I’m pretty confident that it’s working.

Thank you for the clarification. I did read that docs page, however it was not completely clear to me that listing them all was a requirement, but now I realize more how it actually works, so thank you.

And, it does work now. :+1:

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