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

    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):



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

    source = "content"
    target = "content"

    source = "static"
    target = "static"

    source = "layouts"
    target = "layouts"

    source = "data"
    target = "data"

    source = "assets"
    target = "assets"

    source = "i18n"
    target = "i18n"

    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.