‘Embed-nREPL’ is a micro-library to start an nREPL server with my opinionated defaults. I’ve found myself writing this a lot, so it’s time to make it a library!
What are my opinions, I hear you say? Not much.
- I include the default cider-nrepl middleware, at the latest stable version.
- I include the refactor-nrepl middleware, at the latest stable version.
- If piggieback is on the classpath, I include its wrap-cljs-repl middleware.
You can override any of these versions by including an explicit override in your project.clj, or ~/.lein/profiles.clj
Embed-nREPL is on Clojars:
[jarohen/embed-nrepl "0.1.7"]
Getting started:
(require '[nrepl.embed :as nrepl])
;; pop this somewhere, probably in your '-main'
(nrepl/start-nrepl! {:bind "127.0.0.1"
:port 7888
:cljs-opts {...}
:weasel-opts {...}})
;; if you ever need to stop the running nREPL server:
(nrepl/stop-nrepl!)
:bind
is optional, and defaults to =”127.0.0.1”= - set it to
=”0.0.0.0”= to listen on all addresses.
:cljs-opts
and :weasel-opts
are optional - pass any options here
that you want passed to Piggieback and Weasel respectively
start-nrepl!
is idempotent - if there’s already a server started, it
won’t start another.
nREPL embed’s bREPL support is based atop Weasel - thanks Tom Jakubowski!
To open up a CLJS browser REPL, you’ll need to include the following in your project.clj.
;; These can go in your `:dev` profile, if you don't want them to be
;; included as JAR dependencies.
[com.cemerick/piggieback "0.2.1"]
[weasel "0.7.0"]
Then, in your CLJS, include the following to connect to the bREPL on the default port:
(ns myapp.main
(:require [nrepl.embed :refer [connect-brepl!]]))
(connect-brepl!)
;; to customise host/port:
(connect-brepl! {:host "127.0.0.1"
:port 9001})
Finally, once you’ve connected to the server-side REPL, eval:
(nrepl.embed/->brepl)
;; again, to customise the host/port:
(nrepl.embed/->brepl {:host "127.0.0.1"
:port 9001})
Any suggestions/bugs/etc - please report them in the traditional Github manner - cheers! :)
Copyright © 2015 James Henderson
Distributed under the Eclipse Public License, the same as Clojure.