How to use the container Hugo version with One Cli

2019-08-28 22:22发布

问题:

In the Netlify CMS community chat, the question keeps coming up how to manage the Hugo version without a bin folder and executable.

The one-click-hugo-cms example is a deploy to generate a Hugo static site and use Netlify CMS to be able to add posts for the site.

The Issue: The site setup uses a bin folder to store the Hugo executable for simplicity, but the developer wants to use a different version of Hugo and keep it up to date without having to keep copying new executables to the Hugo bin folder.

回答1:

The bin folder for Hugo is NOT required. Netlify manages a Hugo version install in the container based on the environment variable (HUGO_VERSION) when there is a build.

Basically follow these steps:

  • Remove the bin folder and executable out of the project
  • Change the command to the bin path and call it globally
  • Let Netlify know what version you want to use in the netlify.toml

Remove the bin path

Edit this line

const hugoBin = `./bin/hugo.${process.platform === "win32" ? "exe" : process.platform}`;

to be

const hugoBin = 'hugo';

netlify.toml

[build]
  command = "yarn build"
  publish = "dist"
[build.environment]
  YARN_VERSION = "1.3.2"
  HUGO_VERSION = "0.36.1"

[context.deploy-preview]
  command = "yarn build-preview"

NOTES:

  • Make sure on your local development to have Hugo installed in a global path location
  • Netlify installs Hugo version 0.17 by default, so use HUGO_VERSION to specify version
  • Optional way to manage Hugo versions explained here
  • one-click-hugo-cms example repo without bin folder