0
votes

I have a toy-project Clojurescript + reagent and everything works fine for the dev build. Is it possible to start in REPL the mini-fied version ?

I am copying below the project.clj file and the main method of the core.cljs file.

  (defproject reagen-demo22 "0.1.0-SNAPSHOT"
     :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.229"]
                 [reagent "0.6.0"]]

  :min-lein-version "2.5.3"

  :source-paths ["src/clj"]

  :plugins [[lein-cljsbuild "1.1.4"]]

  :clean-targets ^{:protect false} ["resources/public/js/compiled"
                                    "target"]

  :figwheel {:css-dirs ["resources/public/css"]}

  :profiles
  {:dev
   {:dependencies []

    :plugins      [[lein-figwheel "0.5.8"]]
    }}

  :cljsbuild
  {:builds
   [{:id           "dev"
     :source-paths ["src/cljs"]
     :figwheel     {:on-jsload "reagen-demo22.core/reload"}
     :compiler     {:main                 reagen-demo22.core
                    :optimizations        :none
                    :output-to            "resources/public/js/compiled/app.js"
                    :output-dir           "resources/public/js/compiled/dev"
                    :asset-path           "js/compiled/dev"
                    :source-map-timestamp true}}

    {:id           "min"
     :source-paths ["src/cljs"]
     :compiler     {:main            reagen-demo22.core
                    :optimizations   :advanced
                    :output-to       "resources/public/js/compiled/app.js"
                    :output-dir      "resources/public/js/compiled/min"
                    :closure-defines {goog.DEBUG false}
                    :pretty-print    false}}

    ]})

and the main section of the core namespace:

(defn ^:export main []
   (r/render-component 
    [display-the-list]
(.getElementById js/document "app")))

Thank you in advance for any help: link/hint/URL/doc!!

1
Can you provide a little more explanation regarding what your trying to do? What your trying to do doesn't really make sense. Clojurescript is compiled down to javascript using Google's Closure compiler. I don't think you can use figwheel with advanced compilation options. Your also missing a 'min' profile, whiich you need to run your min version with lein. You do have a min build profile.Tim X
Hi Tim , and thanks for answering with all details. I am running the project by executing [lein figwheel dev]; I thought it is enough to change the build name [lein figwheel min] and I can 'see' the optimized version of the toy-project. It did not work. I have tried another approach with the Figwheel controls: [lein figwheel; (start-autobuild min). What is the standard approach to deploy the clojurescript app ? e.g. lein uberjar; and deploy the jar file ? Thank you!dag

1 Answers

1
votes

As this is Clojure and ClojureScript, there is more than one way to solve this problem.

The short answer to your question is that you need to run

lein cljsbuild once min

to build a minified version of your ClojureScript application and then have it served up via a web server. This is assuming your project.clj file is correctly defined.

There are a number of different ways of setting up figwheel (for example, default where it uses its own server to serve the web pages or you can set it pu to use something like jetty, a popular approach when your developing both front-end and back-end code).

The point to note is that figwhell is generally something you only want loaded during development/testing phases and not when you do a production deployment. Likewise, you don't want advanced compilation options (which generates the mimified JS) until you ready to deploy. Figwheel itself will only work correctly when the compilation optimization is set to none and won't work at all when it is set to advanced.

Given that you just want to have a look at how this all works and probably don't want to spend time getting into the nitty gritty until you see there is some value to be had, my recommendation would be to use the Luminus web framework to try things out. This will setup a project with both dev and prod profiles and with figwheel support. It will allow you to also run a production build without having to deploy anything. It will pull in a heap of stuff your probably not itnerested in right now, but you can mostly ignore that to start with.

Once you have tried things out and if you want to take things further, then you need to read the documentation for figwheel and I would suggest trying out something built using the basic figwheel template.

While running the risk of causing more confusion, the answer to your general deployment question is that multiple deployment strategies are supported. You can setup your project.clj file so that it has targets for generating jar/war files which you can deploy into something like tomcat, you can add builds to deploy to things like horuku or aws or you can move things across to a web server manually. It really depends on the preferred workflow you have.

The Details

For the Luminus framework, do

lein new luminus my-proj +cljs

which will setup a luminus based project called my-proj and include support for Clojurescirpt and Figwheel. See the luminus site. Reading the Luminus documentation is also a good idea. It will give you an overview of how some standard things are solved using Clojure. The important thing to note is that Clojure takes a different approach to other languages like Ruby and Python. Rather than pre-defined frameworks, the approach with clojure is to build your own workflow. While this will give you a vary powerful solution which avoids much of the boiler plate code of most establsihed frameworks, it is a little challenging until you get to know what clojure can do and what libraries are avilable. Luminus helps bridge that gap. Many people will start off using something like Luminus and then later, once they have some experience, roll their own solution which just has the bits they want. Think of Luminus as training wheels which will get you started rather than a set framework.

To start a fresh figwheel project, you can try

lein new figwheel my-project

Check out the figwheel documentation at github