Debian Codegraph @

docs/content/en/configuration/module.md

raw
1 ---
2 title: Configure modules
3 linkTitle: Modules
4 description: Configure modules.
5 categories: []
6 keywords: []
7 aliases: [/hugo-modules/configuration/]
8 ---
9
10 {{% include "/_common/gomodules-info.md" %}}
11
12 ## Top-level settings
13
14 This is the default configuration:
15
16 <!-- markdownlint-disable MD049 -->
17 {{< code-toggle file=hugo >}}
18 [module]
19 noProxy = 'none'
20 noVendor = ''
21 private = '*.*'
22 proxy = 'direct'
23 vendorClosest = false
24 workspace = 'off'
25 {{< /code-toggle >}}
26 <!-- markdownlint-enable MD049 -->
27
28 `auth`
29 : {{< new-in 0.144.0 />}}
30 : (`string`) Configures `GOAUTH` when running the Go command for module operations. This is a semicolon-separated list of authentication commands for go-import and HTTPS module mirror interactions. This is useful for private repositories. See `go help goauth` for more information.
31
32 `noProxy`
33 : (`string`) A comma-separated list of [glob patterns](g), matching paths that should not use the [configured proxy server](#proxy).
34
35 `noVendor`
36 : (`string`) A [glob pattern](g) matching module paths to skip when vendoring.
37
38 `private`
39 : (`string`) A comma-separated list of [glob patterns](g), matching paths that should be treated as private.
40
41 `proxy`
42 : (`string`) The proxy server to use to download remote modules. Default is `direct`, which means `git clone` and similar.
43
44 `replacements`
45 : (`string`) Primarily useful for local module development, a comma-separated list of mappings from module paths to directories. Paths may be absolute or relative to the [`themesDir`][].
46
47 {{< code-toggle file=hugo >}}
48 [module]
49 replacements = 'github.com/bep/my-theme -> ../..,github.com/bep/shortcodes -> /some/path'
50 {{< /code-toggle >}}
51
52 `vendorClosest`
53 : (`bool`) Whether to pick the vendored module closest to the module using it. The default behavior 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. Default is `false`.
54
55 `workspace`
56 : (`string`) The Go workspace file to use, either as an absolute path or a path relative to the current working directory. Enabling this activates Go workspace mode and requires Go 1.18 or later. The default is `off`.
57
58 You may also use environment variables to set any of the above. For example:
59
60 ```sh
61 export HUGO_MODULE_PROXY="https://proxy.example.org"
62 export HUGO_MODULE_REPLACEMENTS="github.com/bep/my-theme -> ../.."
63 export HUGO_MODULE_WORKSPACE="/my/hugo.work"
64 ```
65
66 ## Hugo version
67
68 You can specify a required Hugo version for your module in the `module` section. Users will then receive a warning if their Hugo version is incompatible.
69
70 This is the default configuration:
71
72 {{< code-toggle config=module.hugoVersion />}}
73
74 You can omit any of the settings above.
75
76 `extended`
77 : {{< deprecated-in v0.153.0 />}}
78 : (`bool`) Whether the extended edition of Hugo is required, satisfied by installing either the extended or extended/deploy edition.
79
80 > [!NOTE]
81 > The extended version check is disabled in v0.153.2 and later.
82 >
83 > Historically, certain features—specifically WebP encoding and LibSass—required the Hugo Extended binary. However, as of v0.153.0:
84 >
85 > - WebP encoding is now supported in all Hugo editions.
86 > - LibSass has been deprecated in favor of [Dart Sass][], which is compatible with any Hugo edition.
87 >
88 > Because these dependencies no longer require a specialized binary, the internal enforcement check for the extended version has been removed. Site and theme authors are encouraged to use Dart Sass to ensure cross-edition compatibility.
89
90 `max`
91 : (`string`) The maximum Hugo version supported, for example `0.153.0`.
92
93 `min`
94 : (`string`) The minimum Hugo version supported, for example `0.102.0`.
95
96 ## Imports
97
98 {{< code-toggle file=hugo >}}
99 [[module.imports]]
100 disable = false
101 ignoreConfig = false
102 ignoreImports = false
103 path = 'github.com/gohugoio/hugoTestModules1_linux/modh1_2_1v'
104 [[module.imports]]
105 path = 'my-shortcodes'
106 {{< /code-toggle >}}
107
108 `disable`
109 : (`bool`) Whether to disable the module but keep version information in the `go.*` files. Default is `false`.
110
111 `ignoreConfig`
112 : (`bool`) Whether to ignore module configuration files, for example, `hugo.toml`. This will also prevent loading of any transitive module dependencies. Default is `false`.
113
114 `ignoreImports`
115 : (`bool`) Whether to ignore module imports. Default is `false`.
116
117 `noMounts`
118 : (`bool`) Whether to disable directory mounting for this import. Default is `false`.
119
120 `noVendor`
121 : (`bool`) Whether to disable vendoring for this import. This setting is restricted to the main project. Default is `false`.
122
123 `usePackageJSON`
124 : {{< new-in 0.159.0 />}}
125 : (`string`) Whether to use the import's npm dependencies in [hugo mod npm pack](commands/hugo_mod_npm_pack/). One of `auto` (default), `always` or `never`. When set to `auto`, Hugo will enable this if either there is a Hugo config file (e.g. `hugo.toml`) or a `package.hugo.json` file in the module root.
126
127 `path`
128 : (`string`) The module path, either a valid Go module path (e.g., `github.com/gohugoio/myShortcodes`) or the directory name if stored in the [`themesDir`][].
129
130 `version`
131 : {{< new-in 0.150.0 />}}
132 : (`string`) If set to a [version query][], this import becomes a direct dependency, in contrast to dependencies managed by Go modules. See [this issue][] for more information.
133
134 ## Mounts
135
136 {{% glossary-term mount %}}
137
138 > [!IMPORTANT]
139 > If you define one or more mounts to map a file system path to a component path, do not use these legacy configuration settings: [`archetypeDir`][], [`assetDir`][], [`contentDir`][], [`dataDir`][], [`i18nDir`][], [`layoutDir`][], or [`staticDir`][].
140
141 ### Default mounts
142
143 Defining a mount for a component within a project configuration removes the default mount for that component.
144
145 Defining a mount for a component within a module configuration removes all default mounts for that module.
146
147 If you still need any of the default mounts, you must explicitly add them along with the new mount.
148
149 These are the default mounts:
150
151 {{< code-toggle config=module.mounts />}}
152
153 `source`
154 : (`string`) The source directory of the mount. For the main project, this can be either project-relative or absolute. For other modules it must be project-relative.
155
156 `target`
157 : (`string`) Where the mount will reside within Hugo's [unified file system](g). It must begin with one of Hugo's [component](g) directories: archetypes, assets, content, data, i18n, layouts, or static. For example, content/blog.
158
159 `disableWatch`
160 : (`bool`) Whether to disable watching in watch mode for this mount. Default is `false`.
161
162 `excludeFiles`
163 : {{< deprecated-in 0.153.0 />}}
164 : Use the [`files`](#files) setting instead.
165
166 `files`
167 : {{< new-in 0.153.0 />}}
168 : (`[]string`) A [glob slice](g) defining the files to include or exclude.
169
170 `includeFiles`
171 : {{< deprecated-in 0.153.0 />}}
172 : Use the [`files`](#files) setting instead.
173
174 `lang`
175 : {{< deprecated-in 0.153.0 />}}
176 : Use the [`sites`](#sites) setting instead.
177
178 `sites`
179 : {{< new-in 0.153.0 />}}
180 : (`map`) A map to define [sites matrix](g) and [sites complements](g) for the mount. Relevant for `content` and `layouts` mounts, and `static` mounts when in multihost mode. For `static` and `layouts`, only the `matrix` keyword is supported.
181
182 ### Example
183
184 {{< code-toggle file=hugo >}}
185 [module]
186 [[module.mounts]]
187 source = 'content'
188 target = 'content'
189 files = ['! docs/*']
190 [[module.mounts]]
191 source = 'node_modules'
192 target = 'assets'
193 [[module.mounts]]
194 source = 'assets'
195 target = 'assets'
196 {{< /code-toggle >}}
197
198 [Dart Sass]: /functions/css/sass/#dart-sass
199 [`archetypeDir`]: /configuration/all/#archetypedir
200 [`assetDir`]: /configuration/all/#assetdir
201 [`contentDir`]: /configuration/all/#contentdir
202 [`dataDir`]: /configuration/all/#datadir
203 [`i18nDir`]: /configuration/all/#i18ndir
204 [`layoutDir`]: /configuration/all/#layoutdir
205 [`staticDir`]: /configuration/all/#staticdir
206 [`themesDir`]: /configuration/all/#themesdir
207 [this issue]: https://github.com/gohugoio/hugo/pull/13966
208 [version query]: https://go.dev/ref/mod#version-queries