How to generate code constants based on environment?

Hi,

In Purescript Halogen Realworld it says that some hard coded values should be brought from build tools. I was trying to discover how to do that using esbuild but I hadn’t any luck.

Basically I want to have a module (like Config ) with constants like (endpoint :: String) with different values depending on environment. Basically:

module Config where

endpoint = "localhost:8080"

when I’m in dev and

module Config where

endpoint = "api.acme.com"

when I’m in production. I think it is some kind of preprocessing ala Jinja in Python or mustache generically, but I don’t know how to do that with the Purescript + esbuild chain tool.

Any ideas?

See HOW do you read NODE_ENV while bundling? for recommendations.

2 Likes