bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 210 forks source link

How to specify and access environment variables #685

Open dchacke opened 6 years ago

dchacke commented 6 years ago

I understand Figwheel allows me to specify different builds. (Perhaps another way to think of them is as environments?)

Based on the build/environment, I may require a different behavior in my code. For example, when in dev, I connect to a certain API endpoint, and in prod it's a different endpoint. Ideally, I would like some way (presumably this belongs in project.clj) of specifying environment specific variables, and then access them in my cljs code.

Is there a mechanism to do this?

I'm picturing something like this:

:cljsbuild {
    :builds [{:id "dev"
              :source-paths ["src"]
              :figwheel true
              :env-variables {foo "bar"
                              bar "foo"} ; <--------
              :compiler {:main hello-seymore.core 
                         :asset-path "cljs/out"
                         :output-to  "resources/public/cljs/main.js"
                         :output-dir "resources/public/cljs/out"} 
             }
             {:id "prod"
              :env-variables {foo "different value for foo"
                              bar "different value for bar"}}] ; <--------
              ; etc
   }

And then in my cljs code I would like to access them somehow. If it matters, I am running a Reagent project.

bhauman commented 6 years ago

Your going to want to direct this question to the Clojurians slack.

Sign up: http://clojurians.net Sign in: http://clojurians.slack.com

Channels of interest to this topic:

clojurescript