Environment specific Build profiles

Hi Guys, Any idea if Hugo supports build profiles or something similar

I have few properties in json/yaml file and these are environment specific values. If I am running hugo locally, I want to use dev related props while it’s running in prod I want to use prod related properties. Just wondering if this is something possible with existing setup.

Thanks for your time.

1 Like

Use multiple config files config.dev.yml vs. config.stage.yml vs. config.prod.yml.

Then when you run hugo on the command line use the config flag:

hugo --config=site/config.dev.yml

I use node as a build system with hugo rather than using different config files, but it achieves the same goal. You can see a few different npm scripts related to hugo in my package.json file. Here’s my hugo build script which determines whether or not to build drafts, and the base URL to use when building the site.

Thanks @rhewitt @Mikhail . This helps.

You can also override specific settings via OS environment variables, which is super-useful if you are deploying from Netflify or some other CI.

HUGO_THEME=docdock hugo

All upper case, prefix with “HUGO_”

1 Like

As others have suggested, the hugo flags can be leveraged to produce different effects when built. Simply using flags gives you great control and helps you maintain a Twelve-Factor App, which states about config:

Apps sometimes store config as constants in the code. This is a violation of twelve-factor, which requires strict separation of config from code. Config varies substantially across deploys, code does not.

Like @rhewitt suggests you could use NPM scripts, which are really just a convenient way to run little bin scripts (usually written it bash or JS, but certainly not limited to them). Composer JSON files can run bin scripts as well. Or you could simply create a Makefile or Rakefile (plenty to borrow from Jekyll community there) and run flags using IoC pattern, which is very common.

Personally use a Rakefile to create an environment specific build file because and tools written in a number of different languages to build and deploy my Hugo site.

My best advice is to start small and build slowly as the need arises so you know what your getting and how it fits into your workflow. Leveraging existing tools can be great. But they also require maintenance and come with their own associated risks and benefits.

Thanks @bep . This is interesting. Any idea how we can override params defined under “params” like below? Is there any notation for this?

   author = "test"

You can do this easily in the template using the function default

{{ default .Site.Params.author (Something that replaces) }}
1 Like