Orlando Osorio
Orlando Osorio

Reputation: 3125

ClojureScript without Java

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?

Upvotes: 16

Views: 3091

Answers (3)

Gra
Gra

Reputation: 1594

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.

Upvotes: 9

Matthew Molloy
Matthew Molloy

Reputation: 1186

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

Upvotes: 3

JohnJ
JohnJ

Reputation: 4833

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.

Upvotes: 7

Related Questions