Skip to content

Running figwheel in a Cursive Clojure REPL

Bruce Hauman edited this page May 1, 2015 · 39 revisions

Warning! The ClojureScript REPL landscape is changing rapidly, so your mileage may vary.

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

  • figwheel "0.2.9"
  • figwheel-sidecar "0.2.9"
  • lein-figwheel "0.2.9"
  • cursive clojure 0.1.54
  • clojure 1.7.0-beta2
  • clojurescript 0.0-3211

Overview

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

  • Launch figwheel from a terminal
  • Create a remote nrepl "run configuration" in Intellij / Cursive
  • Connect to the remote nrepl server from a Cursive repl
  • Start a figwheel Clojurescript repl on top of the Clojure repl

Launch a figwheel repl

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 projects newly created dir and in the project.clj file, uncomment the line :nrepl-port 7888 (the line is in the :figwheel section).

Next, start figwheel from the terminal with: lein figwheel

Make sure that your ClojureScript app can connect to your figwheel server process by pointing your browser to: http://localhost:3449 (substitute 3449 for whatever port your app is running on. 3449 is the default figwheel development server port).

In Intellij / Cursive, create a "Remote REPL" run configuration

  • Click Run->Edit configurations.
  • Click the + button at the top left and choose "Clojure REPL -> Remote"
  • Enter a name in the name field (e.g. "Remote Figwheel repl")
  • Choose the radio button "Connect to Server"
  • In the host field put localhost
  • In the port field put 7888 (or whatever :nrepl-port you chose in your project.clj file)
  • Click the OK button to save your repl config.

Connect to the remote nRepl Server

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

If everything is configured properly, you should see something similar to the following in the repl window:

Connecting to remote nREPL server...
Loading /Users/yourusername/Library/Application Support/IntelliJIdea14/clojure-plugin/lib/cursive.jar!/cursive/repl/runtime.clj... done
Clojure 1.7.0-beta2

Start a figwheel Clojurescript repl on top of the Clojure repl

In your repl window type:

(use 'figwheel-sidecar.repl-api)
=> nil

then type:

(cljs-repl)

You should see the following if everything is working correctly:

Launching ClojureScript REPL for build: 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

Clone this wiki locally