Add ClojureScript Support

Currently, our guestbook application uses server-side rendering and the browser simply displays a static page.

Let’s modify our project from Chapter 1, Getting Your Feet Wet, to be a single-page application (SPA) using ClojureScript.

Using lein-cljsbuild

The easiest way to add ClojureScript support to a Clojure project is by using the lein-cljsbuild plugin.[38] The plugin compiles the ClojureScript sources and outputs the resulting JavaScript in the specified location.

The first thing we have to do is to add the ClojureScript runtime dependency to our project. Note that it’s scoped as “provided”. Since we’re outputting compiled JavaScript, it only needs to be present for development.

 :dependencies
 [...
  [org.clojure/clojurescript ...

Get Web Development with Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.