Starting a Node.js app with ClojureScript and Boot
I set out to write a Node.js application in ClojureScript, using Boot as my build tool. Because these tools are still young and rapidly evolving, I had to sort through an abundance of incomplete, misleading or out-of-date information to figure it out. For reference, here is an excellent article on how to do the same thing using Leiningen.
tl;dr - here’s the quickstarter kit.
Let’s start off by creating a file
app.core reflects the source file
core.cljs placed in the
app/ directory. We can compile this directly using the ClojureScript compiler:
There are a number of ways to install the ClojureScript compiler, but building it from source worked best for me. If all went well, you can run your app with:
Using the ClojureScript compiler manually can be tricky. If you can’t quite get it to work, don’t worry. We’re going to use the flexible Boot build tool to automate this process.
Let’s create a
build.boot project file:
You can adjust the
boot-cljs version to reflect the latest on Clojars. The point of Boot is to be a flexible build automation system that lets you assemble your own pipeline using a rich assortment of independent composable tasks.
Let’s define a file watcher task that responds to changes by compiling our Node.js app with source mapping enabled:
boot dev should now look something like this:
The app should now appear in the
target/ directory, which is created by the
target task, introduced as a standalone operation in Boot 2.5 (See: Boot 2.5: Slow is smooth, smooth is fast). You must
cd into the
target directory to run the compiled app because at this point it relies on the relative paths of the dependencies generated by the Google Closure Compiler in the
For building the final product, let’s add a
build.boot file will allow you to expand your build configuration as your project evolves. More information about