Fork me on GitHub
#figwheel-main
<
2020-03-10
>
Vitor Barbosa09:03:33

Hello! I was wondering what is the best way to have developer-specific configs for figwheel-main builds? For example, I need each developer to be able to specify :connect-url. Hopefully I would like to do it in a file that is git-ignored, so each dev can keep it's own config there without having to explicitly skip it all the time. At the same time, I want to keep a default for the :connect-url because it is okay for most of the devs. Is there an easy way to achieve this?

pyrmont09:03:53

Does each dev need a differently named file? Or is it enough for each dev to have their own copy of the file?

pyrmont09:03:04

If the latter, you can have an alias in your deps.edn file that passes a build name as an option:

aliases {:fig     {:extra-deps
                      {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
                       com.bhauman/figwheel-main {:mvn/version "0.2.3"}}
                     :extra-paths ["target" "test"]}
           :build   {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]}
           :min     {:main-opts ["-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]}
           :special  {:main-opts ["-m" "figwheel.main" "-b" "special" "-r"]}
           :test    {:main-opts ["-m" "figwheel.main" "-co" "test.cljs.edn" "-m" "pondent.test-runner"]}}}
In that example, you can now have a file called special.cljs.edn that has the connection URL.
^{:watch-dirs ["test" "src"]
  :css-dirs ["resources/public/css"]                     
  :open-url "<http://[%5Bserver-hostname%5D]:%5B%5Bserver-port%5D%5D/index.html|http://[[server-hostname]]:[[server-port]]/index.html>"
  :ring-server-options {:host "[your-url]" :port [your-port]}}                                        
{:main [your-main-ns].core}

pyrmont09:03:09

You'd now start it with clojure -A:fig:special.

pyrmont09:03:47

You can specify a :connect-url in the special.cljs.edn file if that's what you need.

pyrmont09:03:00

Hope that helps.

Vitor Barbosa10:03:44

Thanks @UG9H141FX. Yes it does help. I was wondering that maybe there was a way to "merge" config files "automagically", so I could keep something like app.dev.cljs.edn and have figwheel merge it to an app.cljs.edn. But if there is not, then I'll probably use something similar to your suggestion 😉

pyrmont12:03:26

Yeah, I think your only possibly solution there is to write your own startup script that then manually starts Figwheel. Not quite ideal :(

Vitor Barbosa10:03:31

@UG9H141FX I found a nice solution:

lein 'trampoline' 'run' '-m' 'figwheel.main' '-co' 'dev.cljs.edn' '-fwo' 'figwheel-main.edn:figwheel-main.developer-config.edn' '-c' '-r'

Vitor Barbosa10:03:59

Here figwheel-main.developer-config.edn is git ignored and can have configuration variables specific for each dev

Vitor Barbosa10:03:57

I put this in a makefile so we can just run make run and it will read from figwheel-main.edn and figwheel-main.developer-config.edn and merge the configs from left to right

Vitor Barbosa10:03:26

Here is the relevant part from figwheel --help

-fwo, --fw-opts edn          Options to configure figwheel.main, can be an EDN 
                              string or system-dependent path-separated list of 
                              EDN files / classpath resources. Options will be 
                              merged left to right.