Skip to content

Running figwheel in a Cursive Clojure REPL

Bruce Hauman edited this page Sep 20, 2015 · 39 revisions

This has been tested with the following versions (but may work with other versions as well):

  • figwheel-sidecar "0.4.0"
  • cursive clojure 0.1.62
  • clojure 1.7.0
  • clojurescript 1.7.122

Overview

These are the steps you need to take to get a ClojureScript figwheel REPL going in Intellij: (see full details below)

  • Create a figwheel project and tweak your project.clj
  • Create a script/repl.clj file
  • Create a clojure.main Cursive REPL Configuration

Create figwheel project and tweak your project.clj

Create a new ClojureScript project based on the figwheel template by running lein new figwheel figwheel-test in your terminal.

This will create a figwheel project called figwheel-test based on the figwheel template.

cd into your project's newly created dir and in the project.clj remove lein-figwheel from :plugins. Change your :dependencies to include figwheel-sidecar:

Your :dependencies and :plugins should look like the following:

(defproject figwheel-test "0.1.0-SNAPSHOT"
  ...
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/clojurescript "1.7.122"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [figwheel-sidecar "0.4.0"]]

  :plugins [[lein-cljsbuild "1.1.0"]]
  ...)

Create a script/repl.clj file

Create a script/repl.clj file, it's contents should look like the following:

(use 'figwheel-sidecar.repl-api)
(start-figwheel! {:all-builds (figwheel-sidecar.repl/get-project-cljs-builds)})
(cljs-repl)

note: leiningen profile merging won't occur with figwheel-sidecar.repl/get-project-cljs-builds

Create a clojure.main Cursive REPL Configuration

  • Click Run->Edit configurations.
  • Click the + button at the top left and choose Clojure REPL
  • Choose a Local REPL
  • Enter a name in the Name field (e.g. "REPL")
  • Choose the radio button Use clojure.main in normal JVM process
  • In the Parameters field put script/repl.clj
  • Click the OK button to save your REPL config.

Connect!

In Intellij make sure your REPL config is selected and click the green "play" button to start your REPL.

You should see the following if everything is working correctly:

Focusing on build ids: dev
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild [id ...])      ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (build-once [id ...])           ;; builds source one time
          (clean-builds [id ..])          ;; deletes compiled cljs target files
          (fig-status)                    ;; displays current state of system
          (add-dep [org.om/om "0.8.1"]) ;; add a dependency. very experimental
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: Control+C or :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when figwheel connects to your application
Type `:cljs/quit` to stop the ClojureScript REPL