How to Use Hugo Modules

You'll need to make some minor preparations before using the Hugo modules.
Donate

Become a backer or sponsor to support our work.

On this page

Sponsors

Install Go

See download and install Go for details.

Initialization

Firstly, we need to initialize your site or theme to be a module via hugo mod init MODULE_PATH.

The MODULE_PATH is the identifier of your theme or site, which is usually the repository URL that without protocol, for example,

1hugo mod init example.com/user/repo

Import Modules

Now you’re able to import any modules your want, for example.

hugo.yaml

1module:
2  imports:
3  - path: github.com/hugomods/icons/vendors/bootstrap
4  - path: github.com/hugomods/images
5  - path: github.com/hugomods/bootstrap
6  - path: github.com/hugomods/katex

hugo.toml

1[module]
2  [[module.imports]]
3    path = 'github.com/hugomods/icons/vendors/bootstrap'
4  [[module.imports]]
5    path = 'github.com/hugomods/images'
6  [[module.imports]]
7    path = 'github.com/hugomods/bootstrap'
8  [[module.imports]]
9    path = 'github.com/hugomods/katex'

hugo.json

 1{
 2   "module": {
 3      "imports": [
 4         {
 5            "path": "github.com/hugomods/icons/vendors/bootstrap"
 6         },
 7         {
 8            "path": "github.com/hugomods/images"
 9         },
10         {
11            "path": "github.com/hugomods/bootstrap"
12         },
13         {
14            "path": "github.com/hugomods/katex"
15         }
16      ]
17   }
18}