Jono
Jono

Reputation: 3633

Best practice for changing files automatically once checked in on GitHub

We have two environments. This code can't use environment variables, as it's client-side JavaScript.

We need to change a key in an object based on the environment. I don't want to use an if statement because there are multiple places in code.

I only need to change it on the Semaphore CI deployment environment. I'm thinking maybe post-commit hook might be the best way, and just run a command line tool like sed in it to do something like %s/my_local_web/my_staging_web/g. I'm open to any suggestions, or alternative ways of thinking.

Upvotes: -1

Views: 26

Answers (1)

Chris
Chris

Reputation: 136938

Presumably you're packaging your front-end code with something like webpack or parcel? Both of these tools (and most of their competitors) support environment-specific configuration:

The catch is that environment variables must be provided at build time, not runtime. They get compiled into the tools' output.

Upvotes: 0

Related Questions