/README.md

http://github.com/maxweber/cljs-devmode · Markdown · 140 lines · 108 code · 32 blank · 0 comment · 0 complexity · 6cc2c7830511634b0ed6c9a462e8b9db MD5 · raw file

  1. # cljs-devmode
  2. A development mode for ClojureScript. It allows you to develop Clojure
  3. web applications in combination with ClojureScript seamlessly. You can
  4. develop your normal Clojure web application (with Ring and Compojure
  5. for example) and whenever you change a ClojureScript source file it is
  6. automatically recompiled and you can test the changes in your web
  7. browser.
  8. ## Usage
  9. Follow the [Quick Start
  10. Guide](https://github.com/clojure/clojurescript/wiki/Quick-Start) of
  11. ClojureScript (the bootstrap step is required)
  12. After bootstrapping ClojureScript get cljs-devmode:
  13. git clone git@github.com:maxweber/cljs-devmode.git
  14. In the cljs-devmode folder invoke:
  15. lein cljs-devmode-bootstrap
  16. If you haven't set the $CLOJURESCRIPT_HOME environment variable yet,
  17. then pass the full path to your ClojureScript installation as the
  18. first command line argument.
  19. The cljs-devmode-bootstrap leiningen plugin copies all necessary jar
  20. files into the lib folder of $CLOJURESCRIPT_HOME to make this
  21. development mode work.
  22. ### Start the ClojureScript compiler and cljs-devmode from the REPL
  23. To run the hello sample of ClojureScript in development mode do the
  24. following:
  25. * Start the ./script/repl in the $CLOJURESCRIPT_HOME folder.
  26. * Then invoke this lines on the REPL:
  27. <pre>
  28. (require '[cljs.closure :as cljsc])
  29. (defn compile-fn []
  30. (cljsc/build "samples/hello/src"
  31. {:output-dir "samples/hello/out"
  32. :output-to "samples/hello/hello.js"}))
  33. (use 'cljs-devmode.core)
  34. (start-devmode "samples/hello" compile-fn)
  35. </pre>
  36. * This brings up a Jetty server on port 9090, so open
  37. http://localhost:9090/hello-dev.html to see the hello sample of
  38. ClojureScript. On every request cljs-devmode checks, if any .cljs
  39. file inside samples/hello has changed. In the case of a change the
  40. above defined compile-fn is invoked.
  41. * So change the greeting message inside
  42. samples/hello/src/hello/core.cljs.
  43. * When you refresh the http://localhost:9090/hello-dev.html you will
  44. see the new greeting message.
  45. ### cljs-devmode supports to automate the above steps
  46. Take a look at the
  47. [cljs-devmode-example](https://github.com/maxweber/cljs-devmode-example). In
  48. the project folder of cljs-devmode-example you can invoke:
  49. lein cljs-devmode
  50. This generates a cljs-devmode.sh file in the project folder. The
  51. generated shell script starts the Clojure REPL in the
  52. $CLOJURESCRIPT_HOME folder. Furthermore 'lein cljs-devmode' has also
  53. generated a Clojure script, which is a string inside the shell script
  54. and is passed to the Clojure REPL process for evaluation. This Clojure
  55. script does the same as the script in the previous section. But the
  56. paths are adapted to the current project folder (here the
  57. cljs-devmode-example project). So if you execute the cljs-devmode.sh
  58. script:
  59. chmod 755 cljs-devmode.sh
  60. ./cljs-devmode.sh
  61. Then the ClojureScript compiler and the cljs-devmode are started
  62. automatically.
  63. The cljs-devmode-example also demonstrates how to use the
  64. wrap-cljs-forward Ring middleware. This middleware takes care that all
  65. request to /cljs/* (for example) are forwarded to localhost:9090,
  66. where the cljs-devmode is running. So now you can develop your normal
  67. Clojure web application and let ClojureScript do the JavaScript
  68. part. Whenever you modify a .cljs file the whole ClojureScript project
  69. is automatically recompiled and you can test the changes immediately
  70. in your web browser.
  71. 'lein cljs-devmode' has some defaults / conventions for the folder
  72. structure of the project. But all defaults can be changed through a
  73. :cljs-devmode entry in the project.clj. These would be the default
  74. settings:
  75. (defproject cljs-devmode-example
  76. ...
  77. :cljs-devmode {:dir "PROJECT_HOME/cljs"
  78. :src-dir "PROJECT_HOME/cljs/src"
  79. :output-dir "PROJECT_HOME/cljs/out")
  80. :output-to "PROJECT_HOME/cljs/cljs-devmode-example.js")}
  81. You do not have to specifiy the :cljs-devmode entry inside your
  82. project.clj as long as the folder structure of your project follows
  83. the conventions. Take a look at the folder structure of the
  84. cljs-devmode-example. The whole ClojureScript project is in the cljs/
  85. subfolder. The ClojureScript project itself adheres to the folder
  86. structure of the ClojureScript samples. The :cljs-devmode entry can
  87. also be leveraged to pass additional parameters to the ClojureScript
  88. compiler. As you can see in the above example the :output-dir and
  89. :output-to entries are settings for the ClojureScript compiler, every
  90. additional map entry will also be passed to the ClojureScript compiler.
  91. ## TODOs
  92. This is a really primitive prototype for a ClojureScript development
  93. mode. I only wrote it to get started with ClojureScript in one of my
  94. Clojure web applications.
  95. There are many things which can be improved. For example the
  96. generation of the .sh shell script is a little bit nasty ;-) You can
  97. also let the JVM process of leiningen start the ClojureScript
  98. compiler and the devmode via:
  99. lein cljs-devmode start
  100. But then you will not see the output (stdout and stderr) of the
  101. ClojureScript compiler and therefore you cannot read the helpful error
  102. messages of the ClojureScript compiler. Nevertheless there is no
  103. automated way to do a switch to "production mode" yet (e.g. invoke the
  104. Google Closure Compiler in advanced mode and move the resulting js
  105. file to the public/cljs folder).
  106. ## License
  107. Copyright (C) 2011 Maximilian Weber
  108. Distributed under the Eclipse Public License, the same as Clojure.