Is there a way to in clojure / clojurescript to conditionally compile something depending on whether you're compiling to JVM bytecode of Javascript?
I am writing a small game in ClojureScript but want to keep the majority of the code platform neutral so I can convert to Clojure at some point. I also find that compiling in Clojure is better for finding errors in my code.
I have this working fine by having a directory of clj files that cljsbuild converts to cljs using crossovers.
Where I've come unstuck is trying to use core.async in my clj files. This is needed for cljs:
(ns gaz.system
    (:require-macros [cljs.core.async.macros :refer [go]])
    (:require 
        [cljs.core.async]))
While this is needed for clj to work
(ns gaz.system
    (:require
        [core.async ]))
I'd love to have one file with some form conditional require depending on how it's being compiled. Is that possible at all? Con
Have a look at cljx. It let's you prefix s-expressions with e.g. #+clj or #+cljs to create different code for Clojure and Clojurescript.
Also, though I have not tried it so far, there is lein-dalap which seems to rely on pure, compilable Clojure to generate Clojurescript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With