Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Clojurescript repl/connect to not compile when in production?

In my clojurescript code I have the following:

(defn onload [] (repl/connect "http://localhost:9000/repl"))

(set! (.-onload js/window) onload)

The Clojurescript repl is very useful in development, but I am hesitant to leave it in the code during production. What is the cleanest way to have the above code present during development (simple compilation), but absent during production (advanced compilation)?

like image 237
Stephen Cagle Avatar asked Oct 14 '12 01:10

Stephen Cagle


3 Answers

The modern-cljs tutorial actually describes exactly how to solve this here.

Hope that helps!

like image 63
Mason Stewart Avatar answered Nov 02 '22 16:11

Mason Stewart


Unfortunately there aren't currently any well defined ways to do conditional compilation in ClojureScript.

You could add configuration variables to control whether to start a REPL in a variety of ways, but one quick and easy way would be to get the hostname of the current page, and only invoke repl/connnect if it was "localhost" or whatever other domains you're using for development work.

like image 23
levand Avatar answered Nov 02 '22 16:11

levand


I think a combination of lein2 profiles and cljsbuild src-paths munging can do the trick. eg, create a namespace that simply loads your repl, and exclude it with a profile run for the final compile (possibly might need to create a dummy namespace in another src-path directory).

like image 1
gtrak Avatar answered Nov 02 '22 16:11

gtrak