Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic nREPL / cljs compile / cljs repl / figwheel script for use with clj cli command: `clj build.clj TASK`
(require '[ :as api]
'[clojure.string :as string]
'[figwheel-sidecar.repl-api :as figwheel]
'[figwheel-sidecar.components.nrepl-server :as figwheel.nrepl])
(def source-dir "src")
(def compiler-config
{:main 'app.main
:output-to "target/app.js"
:source-map "target/"
:output-dir "target/out"
:optimizations :advanced})
(def dev-config
(merge compiler-config
{:optimizations :none
:source-map true}))
(def nrepl-options
{:nrepl-port 7890
:nrepl-middleware ["cider.nrepl/cider-middleware"
(def ensure-nrepl-port! #(spit ".nrepl-port" (:nrepl-port nrepl-options)))
(def figwheel-options
{:figwheel-options nrepl-options
:all-builds [{:id "dev"
:figwheel true
:source-paths [source-dir "dev"]
:compiler dev-config}]})
;;; Tasks --------------------------------------------------------------------------------
(defmulti task first)
(defmethod task :default [_]
(task ["repl"]))
(defmethod task "compile" [_]
(api/build source-dir compiler-config))
(defmethod task "repl" [_]
(figwheel.nrepl/start-nrepl-server nrepl-options nil)
(println "Started nREPL server on port:" (:nrepl-port nrepl-options)))
(defmethod task "figwheel" [_]
(figwheel/start-figwheel! figwheel-options)
(task *command-line-args*)
{:paths ["src" "dev"]
{org.clojure/clojure {:mvn/version "1.9.0"}
;; For Spec
org.clojure/test.check {:mvn/version "0.9.0"}
;; ClojureScript
org.clojure/clojurescript {:mvn/version "1.9.946"}
com.cemerick/piggieback {:mvn/version "0.2.2" :exclusions
figwheel-sidecar {:mvn/version "0.5.14" :exclusions
org.clojure/tools.nrepl {:mvn/version "0.2.12"}
cider/cider-nrepl {:mvn/version "0.16.0"}
refactor-nrepl {:mvn/version "2.3.1"}}}

This comment has been minimized.

Copy link

@mwfogleman mwfogleman commented Mar 22, 2018

Robert, are there any adjustments to this pattern that are needed a month later? Perhaps you'd consider making this into a project starter repo...


This comment has been minimized.

Copy link

@PEZ PEZ commented Apr 18, 2018

I used these as a start for a project template of sorts.

I sort of merged the Figwheel starter project and this gist. Planning to create a tutorial for absolute beginners. If I get the time for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment