lein-figwheel icon indicating copy to clipboard operation
lein-figwheel copied to clipboard

How to specify and access environment variables

Open dchacke opened this issue 7 years ago • 1 comments

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.

dchacke avatar Apr 27 '18 05:04 dchacke

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

bhauman avatar Apr 27 '18 10:04 bhauman