   (when-let [server (and join? @(:server repl-env))]
     (.join server)))
 
-(defn update-server-host-port [repl-env [f address-port & args]]
-  (if (and (#{"-s" "--serve"} f) address-port)
-    (let [[_ host port] (re-matches #"(.*):(\d*)" address-port)]
-      (cond-> repl-env
-        (not (string/blank? host)) (assoc-in [:ring-server-options :host] host)
-        (not (string/blank? port)) (assoc-in [:ring-server-options :port] (Integer/parseInt port))))
-    repl-env))
+(defn background-build [cfg {:keys [id config options]}]
+  (let [{:keys [::build ::config repl-env-options] :as cfg}
+        (-> (select-keys cfg [::start-figwheel-options])
+            (assoc :options options
+                   ::build {:id id :config config})
+            update-config)
+        cenv (cljs.env/default-compiler-env)]
+    (println "Figwheel: Starting background autobuild for build: " (:id build))
+    (binding [cljs.env/*compiler* cenv]
+      (bapi/build (apply bapi/inputs (:watch-dirs config)) (:options cfg) cenv)
+      (watch-build (:id build)
+                   (:watch-dirs config)
+                   (:options cfg)
+                   cenv
+                   (select-keys config [:reload-clj-files]))
+      (when (figwheel-mode? cfg)
+        (binding [cljs.repl/*repl-env* (figwheel.repl/repl-env*
+                                        (select-keys repl-env-options
+                                                     [:connection-filter]))]
+          (figwheel.core/start*))))))
+
+(defn start-background-builds [{:keys [::background-builds] :as cfg}]
+  (doseq [build background-builds]
+    (background-build cfg build)))
 
 ;; TODO what happens to inits like --init and --eval in all cases
 

          ["-bo" "--build-once"]
          {:group :cljs.cli/compile :fn build-once-opt
           :arg "build-name"
           :doc (str "The name of a build config to build once.")}}})

;; ----------------------------------------------------------------------------
;; Config

#_(add-to-query "ws://localhost:9500/figwheel-connect?hey=5" {:ab 'ab})

(defn config-connect-url [{:keys [::config repl-env-options] :as cfg} connect-id]
  (let [port (get-in config [:ring-server-options :port] figwheel.repl/default-port)
        host (get-in config [:ring-server-options :host] "localhost")
        connect-url
        (fill-connect-url-template
         (:connect-url config "ws://[[config-hostname]]:[[server-port]]/figwheel-connect")
