configuration.md (6026B)
1 ---
2 title: Configure Modules
3 linktitle: Configure Modules
4 description: This page describes the configuration options for a module.
5 date: 2019-07-24
6 categories: [hugo modules]
7 keywords: [themes, source, organization, directories]
8 menu:
9 docs:
10 parent: "modules"
11 weight: 10
12 weight: 10
13 sections_weight: 10
14 toc: true
15 ---
16
17 ## Module Config: Top level
18
19 {{< code-toggle file="config">}}
20 [module]
21 noVendor = ""
22 proxy = "direct"
23 noProxy = "none"
24 private = "*.*"
25 replacements = ""
26 workspace = ""
27 {{< /code-toggle >}}
28
29
30 noVendor {{< new-in "0.75.0" >}}
31 : A optional Glob pattern matching module paths to skip when vendoring, e.g. "github.com/**"
32
33 vendorClosest {{< new-in "0.81.0" >}}
34 : When enabled, we will pick the vendored module closest to the module using it. The default behaviour is to pick the first. Note that there can still be only one dependency of a given module path, so once it is in use it cannot be redefined.
35
36 proxy
37 : Defines the proxy server to use to download remote modules. Default is `direct`, which means "git clone" and similar.
38
39 noProxy
40 : Comma separated glob list matching paths that should not use the proxy configured above.
41
42 private
43 : Comma separated glob list matching paths that should be treated as private.
44
45 workspace {{< new-in "0.83.0" >}}
46 : The workspace file to use. This enables Go workspace mode. Note that this can also be set via OS env, e.g. `export HUGO_MODULE_WORKSPACE=/my/hugo.work` This only works with Go 1.18+.
47
48 replacements {{< new-in "0.77.0" >}}
49 : A comma separated (or a slice) list of module path to directory replacement mapping, e.g. `github.com/bep/my-theme -> ../..,github.com/bep/shortcodes -> /some/path`. This is mostly useful for temporary locally development of a module, and then it makes sense to set it as an OS environment variable, e.g: `env HUGO_MODULE_REPLACEMENTS="github.com/bep/my-theme -> ../.."`. Any relative path is relate to [themesDir](https://gohugo.io/getting-started/configuration/#all-configuration-settings), and absolute paths are allowed.
50
51 Note that the above terms maps directly to their counterparts in Go Modules. Some of these setting may be natural to set as OS environment variables. To set the proxy server to use, as an example:
52
53 ```
54 env HUGO_MODULE_PROXY=https://proxy.example.org hugo
55 ```
56
57 {{< gomodules-info >}}
58
59 ## Module Config: hugoVersion
60
61 If your module requires a particular version of Hugo to work, you can indicate that in the `module` section and the user will be warned if using a too old/new version.
62
63 {{< code-toggle file="config">}}
64 [module]
65 [module.hugoVersion]
66 min = ""
67 max = ""
68 extended = false
69
70 {{< /code-toggle >}}
71
72 Any of the above can be omitted.
73
74 min
75 : The minimum Hugo version supported, e.g. `0.55.0`
76
77 max
78 : The maximum Hugo version supported, e.g. `0.55.0`
79
80 extended
81 : Whether the extended version of Hugo is required.
82
83 ## Module Config: imports
84
85 {{< code-toggle file="config">}}
86 [module]
87 [[module.imports]]
88 path = "github.com/gohugoio/hugoTestModules1_linux/modh1_2_1v"
89 ignoreConfig = false
90 ignoreImports = false
91 disable = false
92 [[module.imports]]
93 path = "my-shortcodes"
94 {{< /code-toggle >}}
95
96 path
97 : Can be either a valid Go Module module path, e.g. `github.com/gohugoio/myShortcodes`, or the directory name for the module as stored in your themes folder.
98
99 ignoreConfig
100 : If enabled, any module configuration file, e.g. `config.toml`, will not be loaded. Note that this will also stop the loading of any transitive module dependencies.
101
102 ignoreImports {{< new-in "0.80.0" >}}
103 : If enabled, module imports will not be followed.
104
105 disable
106 : Set to `true` to disable the module while keeping any version info in the `go.*` files.
107
108 noMounts {{< new-in "0.84.2" >}}
109 : Do not mount any folder in this import.
110
111 noVendor
112 : Never vendor this import (only allowed in main project).
113
114 {{< gomodules-info >}}
115
116
117 ## Module Config: mounts
118
119 {{% note %}}
120 When the `mounts` config was introduced in Hugo 0.56.0, we were careful to preserve the existing `contentDir`, `staticDir`, and similar configuration to make sure all existing sites just continued to work. But you should not have both: if you add a `mounts` section you should remove the old `contentDir`, `staticDir`, etc. settings.
121 {{% /note %}}
122
123 {{% warning %}}
124 When you add a mount, the default mount for the concerned target root is ignored: be sure to explicitly add it.
125 {{% /warning %}}
126
127 **Default mounts**
128 {{< code-toggle file="config">}}
129 [module]
130 [[module.mounts]]
131 source="content"
132 target="content"
133 [[module.mounts]]
134 source="static"
135 target="static"
136 [[module.mounts]]
137 source="layouts"
138 target="layouts"
139 [[module.mounts]]
140 source="data"
141 target="data"
142 [[module.mounts]]
143 source="assets"
144 target="assets"
145 [[module.mounts]]
146 source="i18n"
147 target="i18n"
148 [[module.mounts]]
149 source="archetypes"
150 target="archetypes"
151 {{< /code-toggle >}}
152
153 source
154 : The source directory of the mount. For the main project, this can be either project-relative or absolute and even a symbolic link. For other modules it must be project-relative.
155
156 target
157 : Where it should be mounted into Hugo's virtual filesystem. It must start with one of Hugo's component folders: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, or `archetypes`. E.g. `content/blog`.
158
159 lang
160 : The language code, e.g. "en". Only relevant for `content` mounts, and `static` mounts when in multihost mode.
161
162 includeFiles (string or slice)
163 : One or more [glob](https://github.com/gobwas/glob) patterns matching files or directories to include. If `excludeFiles` is not set, the files matching `includeFiles` will be the files mounted.
164
165 The glob patterns are matched to the filenames starting from the `source` root, they should have Unix styled slashes even on Windows, `/` matches the mount root and `**` can be used as a super-asterisk to match recursively down all directories, e.g `/posts/**.jpg`.
166
167 The search is case-insensitive.
168
169 {{< new-in "0.89.0" >}}
170
171 excludeFiles (string or slice)
172 : One or more glob patterns matching files to exclude.
173