clojureclojurescriptre-frame

Why are there clj and cljs folders in my lein re-frame template?


Why are there clj and cljs folders in my lein re-frame template as below? And why do they both include files called .core that appear to use the same namespaces? I've been told this is the place to start when learning re-frame, but I cannot find any explanations of why the templates are setup the way they are or created including the content they include.

There is no explanation for any of the boilerplate or code that comes with any lein template which make them very hard to use for beginners.

enter image description here


Solution

  • This setup is used to separate Clojure Backend code from the ClojureScript frontend. It isn't actually necessary and I don't particularly recommend it but I can explain its history and why you'd want to do it.

    For the ClojureScript side it really doesn't matter at all.

    When builing a Clojure Backend you will often deploy in some "uberjar" or "uberwar" setup. This means that all source files and dependencies are packed into one single .jar file (basically just a zip file). This is typically done by including all files from a specified set of directories, so it would include src/clj but not src/cljs. If everything is in one directory it would add the .cljs files as well although they are never used by the Clojure backend. So in essence it just makes your "uberjar" bigger. It is not an important optimizations but some people prefer to keep things lean and clean.

    In addition some developers just prefer to separate the code this way. In this case the template authors did.