Hacker News new | ask | show | jobs
by benjaminjackman 1855 days ago
Random question: Can ClojureScript be compiled in the browser? I only looked at it when it first came out and at that time the ClojureScript compiler only ran via the JVM.
6 comments

There is a new thing, and it's kind of a toy [0]. But it lets you load clojurescript from a script tag, so there is practically no setup needed!!

[0] - https://borkdude.github.io/sci-script-tag/index.html

Worth keeping in mind that that's Small Clojure Interpreter (SCI) which while very cool, isn't ClojureScript. Seems to be running Reagent perfectly fine though, so not sure what the exact differences are, AFAIK, SCI is a subset of Clojure.
Wow sci can run reagent out of the box? That’s not a small feat, excellent work @borkdude!
ClojureScript is self-hosted and thus can be compiled in a browser (see https://clojurescript.io/ for an example).

For most serious usage and projects you will want to use the JVM though.

I think ClojureScript has been able to compile itself since ~2015 if I remember correctly. There is some helper libraries that makes the experience nicer nowadays too, tools like KLIPSE (https://github.com/viebel/klipse)

Here are some starting points:

- https://clojurescript.org/guides/self-hosting

- https://practicalli.github.io/clojurescript/quickstart/self-...

- https://blog.klipse.tech/clojurescript/2016/04/04/self-host-...

Yes.

ClojureScript is self-hosting, and there are helper tools out there like klipse that make it easier to set up.

A more lightweight option is borkdude's SCI (Small Clojure Interpreter) running inside HTML script tags:

https://github.com/borkdude/sci-script-tag

When I work on ClojureScript app I am actually modifying application that is running in the browser, without ever reloading the page. That would not be possible if it could not compile or at least interpret it in the browser.
Hot reload doesn't imply compilation in the browser. For all you know lein could be recompiling via the JVM and sending updated JS files to the browser.
That sounds pretty cool, is there a guide to setting that up?
Sure. I use fighwheel. https://figwheel.org/

Actually, when I develop with clojure, I typically have both backend and frontend running at the same time and I am concurrently modifying both applications without restarting them. This is way, way more convenient than having to restart application and then to bring it to a state to run your test.

This is youtube video from which I learned about fighwheel: https://www.youtube.com/watch?v=j-kj2qwJa_E

Have fun!