How should I use package.hugo.json?

Actually, the package.hugo.json is a template for generating package.json, when executing the hugo mod npm pack, the generated package.json will include the dependencies defined in package.hugo.json from modules and themes.

For example, the theme/module requires katex, the package.hugo.json as follows:

{
  "dependencies": {
    "katex": "^0.16.4"
  }
}

Users need to perform the hugo mod npm pack to pull the dependencies from modules and themes if necessary, the generated package.json as follows.

{
  "comments": {
    "dependencies": {
      "katex": "github.com/razonyang/hugo-lab"
    },
    "devDependencies": {}
  },
  "dependencies": {
    "katex": "^0.16.4"
  },
  "devDependencies": {},
  "name": "exampleSite",
  "version": "0.1.0"
}

Then the user can install or update the all required dependencies.

npm install
npm update

When the module introduced a new feature with new dependencies, those dependencies also need to be declared in package.hugo.json, so that users can install the new dependencies after upgrading the module.

$ cd user-site
$ hugo mod get -u github.com/foo/bar
$ hugo mod npm pack
$ npm update
1 Like