# Adding a \[hugo-module\]/exampleSite

**URL:** <https://discourse.gohugo.io/t/adding-a-hugo-module-examplesite/36518>\
**Category:** tips & tricks\
**Created:** [January 12, 2022, 7:06am UTC](https://discourse.gohugo.io/t/adding-a-hugo-module-examplesite/36518 "2022-01-12T07:06:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [January 12, 2022, 7:06am UTC](https://discourse.gohugo.io/t/adding-a-hugo-module-examplesite/36518/1 "2022-01-12T07:06:23Z")

</div>

Sometimes it’s useful to add a site to test out/preview a Hugo Module (theme/theme component). I have had a rather hacky setup with this before adding a /exampleSite folder.

Yesterday I came up with a much simpler and more robust setup that I thought I should share. It falls into the category _why did I not think about this before_:

It’s all in this commit:

> <https://github.com/bep/docuapi/commit/5bfdc7d366ef2de58dc4e52106ad474d06410907>
>
> Use a replace directive in exampleSite/go.mod to point to the directory above in…stead of the themesDir workaround it replaces. This should make it more robust and be the same setup as people using this theme for real projects.

But the gist of it is:

- Import the modules(s) you’re using in the exampleSite Hugo Module
- For the module that lives in the folder above, just put a replacement directive in go.mod, e.g. `replace github.com/bep/docuapi/v2 => ../`

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [January 12, 2022, 7:07am UTC](https://discourse.gohugo.io/t/adding-a-hugo-module-examplesite/36518/2 "2022-01-12T07:07:55Z")

</div>

Pinned globally on January 12, 2022, 7:07am UTC



---

<div class="post-metadata">

**Author:** ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)\
**Post date:** [January 13, 2022, 5:16am UTC](https://discourse.gohugo.io/t/adding-a-hugo-module-examplesite/36518/3 "2022-01-13T05:16:41Z")

</div>

I’ve been doing something similar for a long time (below) and wonder if there is a reason to prefer one method over the other.

In the exampleSite directory:

go.mod

```auto
module github.com/danielfdickinson/minimal-test-theme-hugo-dfd/exampleSite

go 1.17

```

Standard `go.mod` in the main (theme or module) directory

In `exampleSite/config.toml`

**Note** The mounts aren’t necessary if you don’t do the README in assets things. I do that so that I can use the the README asset via a shortcode in a content page (so the module README is in the exampleSite output).

```auto
[module]
  # For the example site, we need the _current_ theme module from the same repo (path is relative to themes directory)
  # See https://gohugo.io/hugo-modules/configuration/#module-config-top-level (replacements)
  replacements = "github.com/danielfdickinson/minimal-test-theme-hugo-dfd -> ../.."

  [[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"

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

  [[module.imports]]
     path = "github.com/danielfdickinson/minimal-test-theme-hugo-dfd"

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

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

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

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

    [[module.imports.mounts]]
      # Allows us to access the README.md and use it in page (via the ``page-assets`` shortcode in exampleSite)
      source = "README.md"
      target = "assets/README-minimal-test-theme.md"

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

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

```

The full code is here:

> **[minimal-test-theme-hugo-dfd/exampleSite at main ·...](https://github.com/danielfdickinson/minimal-test-theme-hugo-dfd/tree/main/exampleSite)**
>
> main/exampleSite

This isn’t just for themes though; I use it with all my modules, but use above repo to get some basic layouts so I don’t have tons of layout boilerplate bit rotting in different modules.

For example see:

> **[GitHub - danielfdickinson/link-handling-mod-hugo-dfd: Hugo module with...](https://github.com/danielfdickinson/link-handling-mod-hugo-dfd)**
>
> Hugo module with partials and shortcodes for improved link handling, including GitHub compatibility - GitHub - danielfdickinson/link-handling-mod-hugo-dfd: Hugo module with partials and shortcodes ...

HTH!
