16

Is it possible to compile ClojureScript without Java?

I read the clojurescript nodejs quickstart but I see they still use java to compile.

I checked cljs-bootstrap but they also depend on java.

Is there any way to just use npm install and start using clojurescript?

Orlando Osorio
  • 3,116
  • 7
  • 29
  • 52

3 Answers3

8

Now there is Lumo: https://www.npmjs.com/package/lumo-cljs

Lumo is a standalone ClojureScript environment that runs on Node.js and the V8 JavaScript engine. It starts up instantaneously and has out-of-the-box access to the entire Node.js ecosystem.

Lumo also provides a ClojureScript build API, making it possible to compile ClojureScript projects entirely without the JVM, thanks to the experimental JavaScript version of the Google Closure Compiler.

Cheers.

Gra
  • 1,542
  • 14
  • 28
7

Until ClojureScript is self-hosted (implemented in ClojureScript rather than Clojure), Java is needed as well as Node/NPM. However, David Nolen said in his April 20, 2015 talk at Clojure West, relatively little work remains before the compiler can be bootstrapped in itself. [The talk may be interesting to watch for other reasons as well.] So this may change in the not-too-distant future.

JohnJ
  • 4,753
  • 2
  • 28
  • 40
3

As of ClojureScript 1.7 self compilation is now supported, see

This Post

To set up

(ns self-compile.core
  (:require cljs.js))

(set! cljs.js/*eval-fn* cljs.js/js-eval)
(def state (cljs.js/empty-state))

(defn my-compiler [str-to-compile]
  (cljs.js/eval-str state str-to-compile
                  (fn [response]
                    ;evaluated code here
                  ))

The initial compilation must be done on the JVM, however once this is done the function my-compiler above will compile strings. To create a sample project with up to date config use the lein mies template

lein new mies my-project
Will Ness
  • 70,110
  • 9
  • 98
  • 181
Matthew Molloy
  • 1,166
  • 1
  • 10
  • 22
  • I'm not sure how to get started, can you explain a bit more? It seems to me they are still depending on lein which depends on java... let's say I don't have java installed, can I run clojurescript with just nodejs? – Orlando Osorio Aug 07 '15 at 20:53
  • I believe that you need to invoke the JVM at least once to get started, after that you should be all good with just node.js. – Matthew Molloy Aug 09 '15 at 03:55
  • Orlando William, to try clojurescript on nodejs check out https://github.com/whamtet/dogfort – Matthew Molloy Oct 05 '15 at 05:47