What does setting HUGO_ENV to "production" do?

Earlier it was just a convention that you used in your templates. But we formalised it some time ago.

I’ll admit when looking for it now, we should do a better job with the docs.

But in general:

  • running hugo server sets environment to development
  • running hugo sets environment to production
  • set it via flag: hugo --environment foo
  • you can also set these with OS env variables HUGO_ENVIRONMENT or HUGO_ENV

These are used to pick the right configuration.

You can also use them in your template:

{{ hugo.Environment }}
{{ if hugo.IsProduction
//
{{ end }}
3 Likes