Skip to content

Instantly share code, notes, and snippets.

@raheelahmad
Last active September 28, 2017 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raheelahmad/5f0c8f4bf95cac4c3cbbeaaabfa4b079 to your computer and use it in GitHub Desktop.
Save raheelahmad/5f0c8f4bf95cac4c3cbbeaaabfa4b079 to your computer and use it in GitHub Desktop.
Clojurescript setup
(ns client.core
(:require [reagent.core :as reagent]))
(defn mount-root []
(reagent/render [:h1 "Hello There!"]
(.getElementById js/document "app")))
;; this is the init that is called in the HTML below
;; and ends up calling mount-root
(defn ^:export init []
(mount-root))
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link href="css/style.css" rel="stylesheet"/>
</head>
<body>
<div id="app" > </div>
<script src="js/compiled/app.js"></script>
<script>client.core.init();</script>
</body>
</html>

Set up a directory with project.clj below.

Create namespaces in src/clj/server/core.clj and src/cljs/client/core.cljs

Create an index.html as below in resource/public/.

Start two REPLs with ' " (jack-in-cljs)

Then in CLJS repl:

:cljs/quit ;; if we were in the cljs repl already
(use 'figwheel-sidecar.repl-api)
(start-figwheel!) ;; might give you errors if you typed project.clj wrong
(cljs-repl)

Then navigate to (probably) http://localhost:3449

(defproject figwheel-setup "0.0.1-SNAPSHOT"
:description "Trivia Game"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.908"]
[reagent "0.7.0"]]
;; plugins for leiningen
:plugins [
[lein-cljsbuild "1.1.7"] ;; compiler to JS
]
:min-lein-version "2.7.1"
;; specify clojure's main; skip optimizations here
;; REPLACE WITH CORRECT BACKEND NAMESPACE
:main ^:skip-aot server.core
:target-path "target/%s"
;; find compilable files
:source-paths ["src/clj" "src/cljs"]
:test-paths ["test/clj"]
;; only clean compiled & target dirs; forget about the whole project
:clean-targets ^{:project false} ["resources/public/js/compiled"
"target"
"test/js"]
:figwheel {:http-server-root "public"
:nrepl-port 7002
:nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl"]}
;; uberjar profile is to compile to Java
:profiles {:uberjar {:aot :all}
:dev {:dependencies [[figwheel-sidecar "0.5.13"]
[com.cemerick/piggieback "0.2.2"] ;; needed for nREPL
[binaryage/dirac "1.2.16"]
]
:plugins [[lein-figwheel "0.5.13"]
[lein-doo "0.1.7"]]
}}
:cljsbuild {:builds [{:id "dev"
:source-paths ["src/cljs"]
:figwheel {:on-jsload "client.core/mount-root"}
;; REPLACE WITH CORRECT FRONTEND NAMESPACE
:compiler {:main client.core
:output-to "resources/public/js/compiled/app.js"
:output-dir "resources/public/js/compiled/out"
:asset-path "js/compiled/out"
:source-map-timestamp true}}]}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment