Hi all,

Have released the first version of a ClojureScript compiler component, to build and serve ClojureScript files in a Component-based system. (It's in the Phoenix repo at the moment, but can be used as a standalone Component in any other system - you don't need to use Phoenix to use it (although do check it out, it's great! #biased)).

I'm still figuring out how/whether this fits into a normal Reloaded workflow, but would be interested to hear others' thoughts - is this something you'd find useful?


https://github.com/james-henderson/phoenix/tree/master/modules/cljs


Include it in your system map as:

(phoenix.modules.cljs/make-cljs-compiler {:source-path "ui-src"
                                          :target-path "target/cljs/"

                                          :web-context-path "/js"

                                          :main myapp.ui.app

                                          :externs [...]

                                          :modules {...}

                                          :dev {:optimizations :none
                                                :pretty-print? true}

                                          :build {:optimizations :advanced
                                                  :pretty-print? false}})

(the return value of this satisfies com.stuartsierra.component/Lifecycle)

When your system starts, the Component will compile your CLJS, and watch the source-path for changes, re-compiling if necessary. You can then use this Component as a dependency in your web handler - it provides a small Ring handler that'll serve the compiled JS for you:

(ns myapp.handler
  (:require [compojure.core :refer [routes GET]]
            [com.stuartsierra.component :as c]
            [hiccup.page :refer [html5]]
            [modular.ring :refer [WebRequestHandler]]
            [phoenix.modules.cljs :as cljs]))

(defn handle-page [req cljs-compiler]
  (html5
   [:head
    [:title ...]
;; the Component returns the relative path of the JS file,
     ;; for you to include in a <script> tag
     [:script {:src (cljs/path-for-js cljs-compiler)}]
    ...]

   [:body
    ...]))

(defrecord AppHandler []
  WebRequestHandler
  (request-handler [{:keys [cljs-compiler] :as this}]
    (routes
      (GET "/" {:as req}
        (handle-page req cljs-compiler))

      (cljs/cljs-handler cljs-compiler))))

For more details, see the README :)

Big thanks to David Nolan for his recent changes to the ClojureScript compiler, and the improved docs!

James

--
Note that posts from new members are moderated - please be patient with your 
first post.
--- You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to