Up and running with ClojureScript in 2018

Rory Gibson
HackerNoon.com
3 min readOct 31, 2018

--

The ClojureScript (CLJS) story has been moving so quickly for a few years now that occasionally it’s worth putting together a quick post on how to get started with a productive dev environment as simply as possible.

Here’s my version for late 2018 (November).

tl;dr the best way to get rolling is now

First you need a new and up-to-date Clojure.

(or brew upgrade clojure if you already have a 1.9+ version and want to get the latest)

Create the basic project structure:

Create a deps.edn in the project root — this is effectively your build file and for a simple project replaces Leiningen or Boot.

This defines your build profile, keyed under “build” (you can add more, like a productionised, minified one — see future blog posts!)

We need to provide some extra runtime context, though, to get the benefits of hot-reloading.

Also in the project root, create dev.cljs.edn containing:

Let’s create a way of getting it into a browser by creating an index page that references our compiled JS. Put this in resources/public/index.html:

And a CSS file at resources/public/styles.css:

Last, we need some actual ClojureScript!

Create src/my-project/core.cljs

Now you can start it all up with only

That should pop a browser window open straight away, showing your shiny new React application, and drop your Terminal into a REPL with the new Rebel Readline command line editing capabilities.

Editing the ClojureScript (or the CSS) should result in an immediate hot-reload that you see in your browser.

Addendum

I discovered all this while creating Trolley — a simple payments system & shopping cart designed for hackers, makers, bootstrappers and startups.

It’s all written in Clojure(Script), though it works with any technology. There are more blog posts coming, as I’ve learned loads about modern CLJ/CLJS web development recently!

--

--

Rory Gibson
HackerNoon.com

Builds and applies technology. Speaks, mentors, coaches. Founder of Trolley — https://trolley.link