Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto building Clojurescript files for Compojure app

I have a web application where i'm using Compojure on the server and Clojurescript on the client. I'm using the leing-cljsbuild plugin to automatically compile cljs files to js.

I'm able to generate the required client side files and load them in the browser when I set the optimizations to :whitespace or :simple, but when I set optimizations to none, the js files reference their dependencies using the local file-system path, which leads to the files not loading at all in the browser.

So, my question is how do I make the generated files use server urls instead of local file paths when they are generated by the clojurescript compiler.

Here's my project.clj file

(defproject my-proj-clj "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"

  :dependencies [[org.clojure/clojure "1.5.1"]
                 [compojure "1.1.6"]
                 [org.clojure/tools.nrepl "0.2.3"]
                 [hiccup "1.0.3"]
                 [com.novemberain/monger "1.5.0"]
                 [org.clojure/clojurescript "0.0-2127"]
                 [jayq "2.5.0"]
                 ]

  :plugins [[lein-ring "0.8.8"]
            [lein-cljsbuild "1.0.1"] 
            ]

  :ring {:handler my-proj-clj.handler/app
                   }

  :cljsbuild { :builds 
              [{
                :source-paths ["src/my-proj-clj"]
                :compiler {
                           :output-dir "./resources/public/js"
                           :output-to "./resources/public/js/cljs-file.js"  
                           :pretty-print true
                           :source-map "./resources/public/js/cljs-file.js.map"
                           :optimizations :none
                           }}]}  

  :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]]}}
like image 864
jack the lesser Avatar asked Nov 02 '22 08:11

jack the lesser


1 Answers

I believe the only valid optimization values are :whitespace, :simple, or :advanced. See line 96 at https://github.com/emezeske/lein-cljsbuild/blob/1.0.1/sample.project.clj.

Thus I would use :whitespace as the optimization level (at least to get something working).

Per your post, an optimization level of :whitespace works? Thus, perhaps you can elaborate.

What results are you expecting from an optimization level of ":none". How does your expected result differ from what an optimization level of :whitespace produces?

An optimization level of :none means cljsbuild is not generating js from your cljs source (it will generate a few goog.include statements but nothing else). Try using an interactive repl to help you prototype. Try running the following : lein trampoline cljsbuild repl-rhino

Hope that helps.

like image 196
lorinpa Avatar answered Nov 11 '22 16:11

lorinpa