Skip to content

Instantly share code, notes, and snippets.

@robert-stuttaford
Last active August 1, 2018 14:18
Show Gist options
  • Save robert-stuttaford/b03de6eade713cea49c0411e6f817813 to your computer and use it in GitHub Desktop.
Save robert-stuttaford/b03de6eade713cea49c0411e6f817813 to your computer and use it in GitHub Desktop.
Basic nREPL / cljs compile / cljs repl / figwheel script for use with clj cli command: `clj build.clj TASK`
(require '[cljs.build.api :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/app.js.map"
: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"
"refactor-nrepl.middleware/wrap-refactor"
"cemerick.piggieback/wrap-cljs-repl"]})
(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" [_]
(ensure-nrepl-port!)
(figwheel.nrepl/start-nrepl-server nrepl-options nil)
(println "Started nREPL server on port:" (:nrepl-port nrepl-options)))
(defmethod task "figwheel" [_]
(ensure-nrepl-port!)
(figwheel/start-figwheel! figwheel-options)
(figwheel/cljs-repl))
(task *command-line-args*)
{:paths ["src" "dev"]
:deps
{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
[com.google.javascript/closure-compiler]}
figwheel-sidecar {:mvn/version "0.5.14" :exclusions
[com.google.javascript/closure-compiler]}
;; REPL
org.clojure/tools.nrepl {:mvn/version "0.2.12"}
cider/cider-nrepl {:mvn/version "0.16.0"}
refactor-nrepl {:mvn/version "2.3.1"}}}
@PEZ
Copy link

PEZ commented Apr 18, 2018

I used these as a start for a project template of sorts. https://github.com/PEZ/deps-edn-figwheel

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