Execute compiled ClojureScript from the commandlin

2019-08-24 15:26发布

I understand ClojureScript can be executed within a JavaScript REPL or it can be compiled into JavaScript, then run in a browser. I couldn't find a way to use it on the server side with Rhino. Here is my way of thinking, I have a simple source file:

(ns simple.hello)

(println "Hello, world")

I compile it to hello.js. I try to run

java -jar js.jar out/goog/base.js out/goog/deps.js out/hello.js

Nothing happens. How can I make it work, or is only Node.js supported on the command line?

1条回答
祖国的老花朵
2楼-- · 2019-08-24 16:27

This works for me:

src/app.js:

(ns simple.app)

(ns hello)
(defn ^:export greet [n]
  (print (str "Hello " n)))

(greet "World")

To compile:

cljsc src '{:optimizations :advanced}' > app-prod.js

Then, to run with Rhino:

java -jar js.jar app-prod.js 

Output: Hello World

Hope that helps!

查看更多
登录 后发表回答