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

Ease usage of `:active-profiles` #679

Open thatismatt opened 6 years ago

thatismatt commented 6 years ago

I've just happened upon a workaround for getting lein profiles working from nrepl. My usecase is multiple figwheel "instances" within one lein project. I thought it was useful enough to share.

project.clj

 ... 8< ...

  ;; defaults
  :figwheel {:server-port  3449 ... }

  ;; overrides for foo
  :profiles {:foo {:figwheel {:server-port 3447 ... }}}

 ... 8< ...

 :cljsbuild
  {:builds
   [;; default - bar
    {:id"bar-build-id" ...}
    ;; foo
    {:id"foo-build-id" ...}]}

 ... 8< ...

dev/user.clj

(ns user
  (:require [figwheel-sidecar.repl-api :as f]
            [figwheel-sidecar.config :as fc]
            [simple-lein-profile-merge.core :as lm]))

(def foo-profiles
  (conj lm/default-profiles :foo))

(defn fetch-foo-config
  []
  (assoc (fc/initial-config-source)
         :active-profiles foo-profiles))

(defn start-foo-figwheel!
  []
  (f/start-figwheel!
   (fetch-foo-config)
   "foo-build-id"))

It might also be nice to extend start-figwheel! to accept additional profiles to be merged in, so that the above could be simplified to something like:

(f/start-figwheel! "foo-build-id" :profiles [:foo])

If this is of interest, let me know and I'll look in to putting a PR together.