Skip to content

Instantly share code, notes, and snippets.

@jmreidy
Last active August 29, 2015 14:14
Show Gist options
  • Save jmreidy/6d42b5d1478d5bb4e293 to your computer and use it in GitHub Desktop.
Save jmreidy/6d42b5d1478d5bb4e293 to your computer and use it in GitHub Desktop.
CLJS setup
(ns project-name.server
(:require [clojure.java.io :as io]
[project-name.dev :refer [is-dev? inject-devmode-html]]
[compojure.core :refer [GET defroutes]]
[compojure.route :refer [resources]]
[compojure.handler :refer [api]]
[net.cgrand.enlive-html :refer [deftemplate]]
[net.cgrand.reload :refer [auto-reload]]
[ring.middleware.reload :as reload]
[environ.core :refer [env]]
[org.httpkit.server :refer [run-server]]))
(deftemplate page
(io/resource "index.html") [] [:body] (if is-dev? inject-devmode-html identity))
(defroutes routes
(resources "/")
(GET "/*" req (page)))
(def http-handler
(if is-dev?
(reload/wrap-reload (api #'routes))
(api routes)))
(defn run [& [port]]
(defonce ^:private server
(do
(when is-dev?
(auto-reload *ns*)
)
(let [port (Integer. (or port (env :port) 10555))]
(print "Starting web server on port" port ".\n")
(run-server http-handler {:port port
:join? false}))))
server)
(defn -main [& [port]]
(run port))
(ns project-name.dev
(:require [project-name.core :as core]
[figwheel.client :as figwheel :include-macros true]
))
(enable-console-print!)
(figwheel/start {
:websocket-url "ws://localhost:3449/figwheel-ws"
:jsload-callback (fn [] (core/main))})
(core/main)
(defproject project-name "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:source-paths ["src/clj" "src/cljs"]
:dependencies [[org.clojure/clojure "1.7.0-alpha5"]
[org.clojure/clojurescript "0.0-2727" :scope "provided"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
;server
[http-kit "2.1.19"]
[ring "1.3.2"]
[ring/ring-defaults "0.1.2"]
[compojure "1.3.1"]
[jmreidy/clj-orchestrate "0.1.0"]
[enlive "1.1.5"]
;client
[org.omcljs/om "0.8.8"]
[prismatic/om-tools "0.3.10"]
;env
[figwheel "0.2.3-SNAPSHOT"]
[figwheel-sidecar "0.2.3-SNAPSHOT"]
[environ "1.0.0"]
]
:plugins [[lein-cljsbuild "1.0.4"]
[lein-environ "1.0.0"]]
:min-lein-version "2.5.0"
:uberjar-name "project-name.jar"
:cljsbuild {:builds {:app {:source-paths ["src/cljs"]
:compiler {:output-to "resources/public/js/app.js"
:output-dir "resources/public/js/out"
:source-map "resources/public/js/out.js.map"
:optimizations :none
:pretty-print true}}}}
:profiles {:dev {:repl-options {:init-ns project-name.server}
:plugins [[lein-figwheel "0.2.3-SNAPSHOT"]]
:figwheel {:http-server-root "public"
:server-port 3449
:css-dirs ["resources/public/css"]}
:env {:is-dev true}
:cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"]}}}}
:uberjar {:hooks [leiningen.cljsbuild]
:env {:production true}
:omit-source true
:aot :all
:cljsbuild {:builds {:app
{:source-paths ["env/prod/cljs"]
:compiler
{:optimizations :advanced
:pretty-print false}}}}}})
@jmreidy
Copy link
Author

jmreidy commented Feb 7, 2015

This is my basic CLJS dev setup, based off Chestnut but using the newest Figwheel. Within Cursive Clojure, I start up a REPL and invoke (run) to get my ring server going.

I then open up the Cursive "Terminal" window and invoke lein figwheel, which sets up my CLJS autocompilation and loads the new Fighweel repl in the terminal.

This approach allows me to have my src editor in the main window, with my server repl on the right and my browser repl on the bottom. I enjoy having both REPLs available, as opposed to using piggieback to "clobber" my server REPL. And Cursive means that I get easy window management for keeping track of everything.

@bcg
Copy link

bcg commented Feb 7, 2015

Awesome. Thanks!

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