Just sharing the stopgap method for "static HTML" (no server)
ClojureScript development I'm using until someone cooks up a REPL that
evals in the browser instead of Rhino.

Nothing particularly exciting here, but really beats restarting the JVM
on every compile. :-)

This will only work on Linux as is but could be trivially adapted to any
OS that has an equivalent to inotifywait.  (JDK 7 will have an API for it.)

1. Install your distro's inotify-tools package.
2. Adjust the paths in the code below to suit your project.
3. Run ClojureScript's ./script/repl and paste in the code below.
4. Point your favourite editor and web browser at your project.

Now use a workflow something like this:

1. In the editor make a code change and save it.
2. Flip to browser and refresh to test it.
3. Repeat until done.

Here's the code:

    (require '[cljs.closure :as cljsc])

    (defn await-change [path]
      (-> (Runtime/getRuntime)
          (.exec (into-array ["inotifywait" "-qre" "modify" path]))
          (.waitFor)))

    (let [root "/home/ato/src/myproject"]
      (while true
        (println "Compiling...")

        (time
         (cljsc/build
          (str root "/src/myproject/core.cljs")
          {:optimizations nil      ; vs :simple or :advanced
           :target nil             ; vs :nodejs
           :pretty-print true
           :output-dir (str root "/out")
           :output-to (str root "/myproject.js")}))

        (await-change (str root "/src"))))

Hints:

1. Avoid optimizations :simple or :advanced when you can while
developing.  On my PC after the JVM warms up a basic compile takes 30ms
while :simple or :advanced take at least 1 second.

2. If there's a compile error you might not notice it.  Position your
terminal somewhere you can easily see from both editor and browser.

3. I highly recommend global hot-keying your browser, editor and
terminal somehow.  You could use virtual desktops.  Me, I use the same
three tools for all my work so I just have Super-w, Super-e and Super-d
focus each respectively.

4. The same method works well for any compiled language that lacks an
interactive dev environment.  When I'm working on C code I just run
this in a terminal:

    while inotifywait -qre modify src; make && ./myprogram; done

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to