Skip to content

Instantly share code, notes, and snippets.

@bhauman bhauman/README.md
Last active Apr 14, 2019

Embed
What would you like to do?
ClojureScript minimal dev and prod setup.

Recent improvements to the ClojureScript compiler have greatly simplified setting up development versus production outputs.

This example uses Figwheel as something that you want to exclude for production, but the pattern is general.

With this simple setup you only need one html file/view and it will work for developement and production.

(ns hello_world.dev
(:require
[hello_world.core] ;; <<<<--- require your main namespace
[figwheel.client :as fw]))
;; do things you don't want to happen in production
(fw/start {
:websocket-url "ws://localhost:3449/figwheel-ws" })
<!DOCTYPE html>
<!-- you only need one html file for dev and prod -->
<html>
<head>
</head>
<body>
<div id="app"><h1>Hi.</h1></div>
<!-- only need one script tag for dev and prod -->
<script src="hello_world.js" type="text/javascript"></script>
</body>
</html>
(defproject hello_world "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2727"] ;; <<<<--- this was available as of 2727
[figwheel "0.2.3-SNAPSHOT"]]
:plugins [[lein-cljsbuild "1.0.4"]
[lein-figwheel "0.2.3-SNAPSHOT"]]
:source-paths ["src"]
:cljsbuild {
:builds [{:id "dev"
:source-paths ["src" "dev_src"]
:compiler {:output-to "hello_world.js"
:output-dir "out"
:optimizations :none
:main hello_world.dev ;; <<<--- the entry point is a dev namespace
;; it will set up a dev env and require your
;; main app namespace
:asset-path "out"
:source-map true
:source-map-timestamp true
:cache-analysis true }}
{:id "min"
:source-paths ["src"] ;; <<<<--- the dev source directory is excluded so no dev code
:compiler {:output-to "hello_world.js"
:optimizations :advanced
:pretty-print false}}]})
(ns ^:figwheel-always hello_world.core)
;; this is your main application namespace
(enable-console-print!)
(println "Hello world!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.