Re: Complete Web Development Setup Using Clojure CLI Tools

2020-04-27 Thread Jag Gunawardana
Thanks Gary for posting this up. Was a great help for a slightly different 
use case. I was using static site generators like Hugo, but always found 
that I ended up having to learn their internals/templating to make larger 
changes. I also wanted to use Clojurescript and it was painful to do so. I 
made a few changes:

I used the Stasis library to turn my hiccup and assets into a static site 
(but serve up with Ring in development).
I used shadow-cljs to compile my Clojurescript.
I also use deps.edn rather than Lein (even though Lein still feels easier).
My final artifact was a largely static website, packaged up into an Nginx 
docker. I have a small amount of clojurescript which gets built into one 
main.js file.

I can post up the details/a repo if anyone else wants to do similar.

I always feel that you can do pretty much anything with Clojure(script), 
but sometimes there is a bit of a dark art to getting there. I think I 
would use this approach for any site that I would have used a static site 
generator for now. 


On Monday, 9 July 2018 17:14:22 UTC+1, Gary Johnson wrote:
>
> Howdy Clojurians,
>
> I recently started developing a new Clojure+Clojurescript web application, 
> and I wanted to see if I could set up my development environment using just 
> the Clojure CLI tools. After a good deal of digging around through 
> tutorials on a number of different websites and a fair amount of 
> experimenting, I've managed to create a very simple (IMHO) configuration 
> that provides me with both development and production mode CLJS->JS 
> compilation, development and production mode ring handlers, and the always 
> delightful FIgwheel development environment all from just the simple 
> "clojure" command. Since I haven't seen this before, I thought I'd share it 
> with all of you in case it helps someone else out there who doesn't need 
> (or want) all of leiningen or boot to develop a simple web app.
>
> Here goes:
>
> Step 1: Create your project structure like so:
>
> ├── cljsbuild.edn
> ├── deps.edn
> ├── figwheel.edn
> ├── resources
> │   └── public
> │   ├── cljs
> │   ├── css
> │   │ ├── style.css
> │   ├── images
> │   └── js
> ├── src
> │   ├── clj
> │   │   └── my_project
> │   │   ├── handler.clj
> │   │   ├── server.clj
> │   │   ├── views.clj
> │   └── cljs
> │   └── my_project
> │   ├── client.cljs
>
> Step 2: Make the deps.edn file (replace :deps and my-project.server 
> namespace as necessary for your project)
>
> {:paths ["src/clj" "resources"]
>
>  :deps {org.clojure/clojure   {:mvn/version "1.9.0"}
> org.clojure/clojurescript {:mvn/version "1.10.312"}
> ring  {:mvn/version "1.7.0-RC1"}
> ring/ring-defaults{:mvn/version "0.3.2"}
> prone {:mvn/version "1.6.0"}
> compojure {:mvn/version "1.6.1"}
> hiccup{:mvn/version "1.0.5"}
> reagent   {:mvn/version "0.8.1"}}
>
>  :aliases {:run{:main-opts ["-m" "my-project.server"]}
>:cljsbuild  {:extra-paths ["src/cljs"]
> :main-opts ["-m" "cljs.main" "-co" "cljsbuild.edn" 
> "-c"]}
>:figwheel   {:extra-deps {org.clojure/tools.nrepl {:mvn/version 
> "0.2.13"}
>  cider/cider-nrepl   {:mvn/version 
> "0.17.0"}
>  com.cemerick/piggieback {:mvn/version 
> "0.2.2"}
>  figwheel-sidecar{:mvn/version 
> "0.5.14"}}
> :main-opts ["-e" 
> "(use,'figwheel-sidecar.repl-api),(start-figwheel!)"]}}}
>
>
> Step 3: Make the cljsbuild.edn file (replace :main for your project)
>
> {:main  "my-project.client"
>  :output-dir"resources/public/cljs"
>  :output-to "resources/public/cljs/app.js"
>  :source-map"resources/public/cljs/app.js.map"
>  :optimizations :advanced
>  :pretty-print  false}
>
> Step 4: Make the figwheel.edn file (replace :ring-handler, :on-jsload, and 
> :main for your project)
>
> {:nrepl-port   7000
>  :nrepl-middleware ["cider.nrepl/cider-middleware"
> "cemerick.piggieback/wrap-cljs-repl"]
>  :server-port  3000
>  :ring-handler my-project.handler/development-app
>  :http-server-root "public"
>  :css-dirs ["resources/public/css"]
>  :builds [{:id   "dev"
>:source-paths ["src/cljs"]
>:figwheel {:on-jsload "my-project.client/mount-root"}
>:compiler {:main  "my-project.client"
>   :output-dir"resources/public/cljs/out"
>   :output-to "resources/public/cljs/app.js"
>   :asset-path"/cljs/out"
>   :source-maptrue
>   :optimizations :none
>   :pretty-print  true}}]}
>
>
> Step 5: Write se

Re: Complete Web Development Setup Using Clojure CLI Tools

2020-04-27 Thread raybaq
Hi Jag,

Would love to learn more about your approach.  I have just gotten started 
with shadow-cljs.  I read about Stasis some time ago but havent actually 
used it.

TIA,

Ray

On Monday, April 27, 2020 at 8:24:22 PM UTC+8, Jag Gunawardana wrote:
>
> Thanks Gary for posting this up. Was a great help for a slightly different 
> use case. I was using static site generators like Hugo, but always found 
> that I ended up having to learn their internals/templating to make larger 
> changes. I also wanted to use Clojurescript and it was painful to do so. I 
> made a few changes:
>
> I used the Stasis library to turn my hiccup and assets into a static site 
> (but serve up with Ring in development).
> I used shadow-cljs to compile my Clojurescript.
> I also use deps.edn rather than Lein (even though Lein still feels easier).
> My final artifact was a largely static website, packaged up into an Nginx 
> docker. I have a small amount of clojurescript which gets built into one 
> main.js file.
>
> I can post up the details/a repo if anyone else wants to do similar.
>
> I always feel that you can do pretty much anything with Clojure(script), 
> but sometimes there is a bit of a dark art to getting there. I think I 
> would use this approach for any site that I would have used a static site 
> generator for now. 
>
>
> On Monday, 9 July 2018 17:14:22 UTC+1, Gary Johnson wrote:
>>
>> Howdy Clojurians,
>>
>> I recently started developing a new Clojure+Clojurescript web 
>> application, and I wanted to see if I could set up my development 
>> environment using just the Clojure CLI tools. After a good deal of digging 
>> around through tutorials on a number of different websites and a fair 
>> amount of experimenting, I've managed to create a very simple (IMHO) 
>> configuration that provides me with both development and production mode 
>> CLJS->JS compilation, development and production mode ring handlers, and 
>> the always delightful FIgwheel development environment all from just the 
>> simple "clojure" command. Since I haven't seen this before, I thought I'd 
>> share it with all of you in case it helps someone else out there who 
>> doesn't need (or want) all of leiningen or boot to develop a simple web app.
>>
>> Here goes:
>>
>> Step 1: Create your project structure like so:
>>
>> ├── cljsbuild.edn
>> ├── deps.edn
>> ├── figwheel.edn
>> ├── resources
>> │   └── public
>> │   ├── cljs
>> │   ├── css
>> │   │ ├── style.css
>> │   ├── images
>> │   └── js
>> ├── src
>> │   ├── clj
>> │   │   └── my_project
>> │   │   ├── handler.clj
>> │   │   ├── server.clj
>> │   │   ├── views.clj
>> │   └── cljs
>> │   └── my_project
>> │   ├── client.cljs
>>
>> Step 2: Make the deps.edn file (replace :deps and my-project.server 
>> namespace as necessary for your project)
>>
>> {:paths ["src/clj" "resources"]
>>
>>  :deps {org.clojure/clojure   {:mvn/version "1.9.0"}
>> org.clojure/clojurescript {:mvn/version "1.10.312"}
>> ring  {:mvn/version "1.7.0-RC1"}
>> ring/ring-defaults{:mvn/version "0.3.2"}
>> prone {:mvn/version "1.6.0"}
>> compojure {:mvn/version "1.6.1"}
>> hiccup{:mvn/version "1.0.5"}
>> reagent   {:mvn/version "0.8.1"}}
>>
>>  :aliases {:run{:main-opts ["-m" "my-project.server"]}
>>:cljsbuild  {:extra-paths ["src/cljs"]
>> :main-opts ["-m" "cljs.main" "-co" 
>> "cljsbuild.edn" "-c"]}
>>:figwheel   {:extra-deps {org.clojure/tools.nrepl {:mvn/version 
>> "0.2.13"}
>>  cider/cider-nrepl   {:mvn/version 
>> "0.17.0"}
>>  com.cemerick/piggieback {:mvn/version 
>> "0.2.2"}
>>  figwheel-sidecar{:mvn/version 
>> "0.5.14"}}
>> :main-opts ["-e" 
>> "(use,'figwheel-sidecar.repl-api),(start-figwheel!)"]}}}
>>
>>
>> Step 3: Make the cljsbuild.edn file (replace :main for your project)
>>
>> {:main  "my-project.client"
>>  :output-dir"resources/public/cljs"
>>  :output-to "resources/public/cljs/app.js"
>>  :source-map"resources/public/cljs/app.js.map"
>>  :optimizations :advanced
>>  :pretty-print  false}
>>
>> Step 4: Make the figwheel.edn file (replace :ring-handler, :on-jsload, 
>> and :main for your project)
>>
>> {:nrepl-port   7000
>>  :nrepl-middleware ["cider.nrepl/cider-middleware"
>> "cemerick.piggieback/wrap-cljs-repl"]
>>  :server-port  3000
>>  :ring-handler my-project.handler/development-app
>>  :http-server-root "public"
>>  :css-dirs ["resources/public/css"]
>>  :builds [{:id   "dev"
>>:source-paths ["src/cljs"]
>>:figwheel {:on-jsload "my-project.client/mount-root"}
>>:compiler {:main  "my-pro