Skip to content

Instantly share code, notes, and snippets.

Last active December 3, 2019 16:43
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.

[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 -->
<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>
(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 ;; <<<--- 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
(println "Hello world!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment