In other projects where I am using Webpack I often access environment variables with process.env.SOME_API_KEY or process.env.NODE_ENV.
In Hugo I can do something similar with getenv "SOME_API_KEY". But this is not exposed to JavaScript/TypeScript files compiled with Hugo as far as I can tell. So instead I have resorted to this workaround:
That probably won’t happen because it’s basically already built in. Have a look a the defines parameter:
defines [map]
Allow to define a set of string replacement to be performed when building. Should be a map where each key is to be replaced by its value.
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}