I'm trying to figure out the relationship between ClojureScript crossovers and the cljx pre-processor.
Are they designed to be used together? Or rival solutions to the same problem?
Is one becoming the preferred or more standard way to do things?
In particular what I want to do is to create a single library that can be compiled as Clojure and ClojureScript (with a couple of variations). I'm currently using cljx for this.
But then I want to include the library in further clj and cljx projects. Looking for information about this, I'm largely coming across documentation for crossovers but not cljx.
Crossovers, CLJX, and Feature Expressions (from oldest to newest) have some overlap of features useful for compiling to clojure and clojurescript. Cljx and Features Expressions hold promise for more than just clojurescript, though, and make it possible to maintain more than just clojure-java and clojure-js, such as .net (clr, mono). Cljx and Feature Expressions enable arbitrary "features" such as enabling tracing or special "debug" builds.
lein-cljsbuild has deprecated the Crossovers feature. (See https://github.com/emezeske/lein-cljsbuild)
(cljsbuild crossovers are deprecated, and will be removed in v2.x [coming later in 2014].)
I've used CLJX to target Clojure, ClojureClr, ClojureScript (for browsers), and ClojureScript for NodeJS. It works well enough - certainly better than maintaining 4 separate codebases. I haven't used CLJX to do dependencies of dependencies, though once you've packaged a library, it shouldn't matter that it was originally cljx.
This idea borrows from Common Lisp's feature expressions and looks much like cljx.
As of November 2014, this is in the Release.Next, so that sounds promising. It seems that CLJX and LISP's feature expressions are the inspiration for this anticipated feature of Clojure.
I used Crossovers for one project a couple years ago, but since CLJX came out, I've been using CLJX with great success. It takes a little adjustments to tooling and editors, but I believe it is so much better than making the same code change for all the platforms.
I plan to use CLJX until feature expressions are available, and then re-evaluate.
Crossovers and cljx are rival solutions the same problem and cannot be used together. From what I can tell, cljx is preferred over crossovers. For example, as @Hendekagon pointed out, lein-cljsbuild
has deprecated crossovers.
chord
is a library that is intended for both client and server side usage. You could probably use their project.clj
as a starting point.
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