├── resources └── .keep ├── .gitignore ├── CHANGELOG.md ├── deps.edn ├── pom.xml ├── README.md └── src └── practicalli └── hot_loading.clj /resources/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | *.jar 5 | *.class 6 | /.cpcache 7 | /.lein-* 8 | /.nrepl-history 9 | /.nrepl-port 10 | .hgignore 11 | .hg/ 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). 3 | 4 | ## [Unreleased] 5 | ### Changed 6 | 7 | ### Removed 8 | 9 | ### Fixed 10 | 11 | 12 | ## [0.0.1] - 2021-02-14 13 | ### Added 14 | - New project created with Clojure CLI tools and clj-new app template 15 | - Simple webapp created with REPL driven development and hotloading of libraries using add-libs 16 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;; Project Configuration with Hotload 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | 5 | ;; Hotload requires 6 | #_(ns deps.edn 7 | (:require [clojure.tools.deps.alpha.repl :refer [add-libs]])) 8 | 9 | ;; Project configuration 10 | {:paths 11 | ["src" "resources"] 12 | 13 | :deps 14 | #_ (add-libs) 15 | {org.clojure/clojure {:mvn/version "1.10.1"} 16 | http-kit/http-kit {:mvn/version "2.5.1"} 17 | hiccup/hiccup {:mvn/version "2.0.0-alpha2"}} 18 | 19 | :aliases 20 | { 21 | :test 22 | {:extra-paths ["test"] 23 | :extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}}} 24 | 25 | :runner 26 | {:extra-deps {com.cognitect/test-runner 27 | {:git/url "https://github.com/cognitect-labs/test-runner" 28 | :sha "b6b3193fcc42659d7e46ecd1884a228993441182"}} 29 | :main-opts ["-m" "cognitect.test-runner" 30 | "-d" "test"]} 31 | 32 | :uberjar 33 | {:extra-deps {seancorfield/depstar {:mvn/version "1.1.128"}} 34 | :main-opts ["-m" "hf.depstar.uberjar" "hot-loading.jar" 35 | "-C" "-m" "practicalli.hot-loading"]}}} 36 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | practicalli 5 | hot-loading 6 | 0.1.0-SNAPSHOT 7 | practicalli/hot-loading 8 | FIXME: my new application. 9 | https://github.com/practicalli/hot-loading 10 | 11 | 12 | Eclipse Public License 13 | http://www.eclipse.org/legal/epl-v10.html 14 | 15 | 16 | 17 | 18 | Practicalli 19 | 20 | 21 | 22 | https://github.com/practicalli/hot-loading 23 | scm:git:git://github.com/practicalli/hot-loading.git 24 | scm:git:ssh://git@github.com/practicalli/hot-loading.git 25 | HEAD 26 | 27 | 28 | 29 | org.clojure 30 | clojure 31 | 1.10.1 32 | 33 | 34 | 35 | src 36 | 37 | 38 | 39 | clojars 40 | https://repo.clojars.org/ 41 | 42 | 43 | sonatype 44 | https://oss.sonatype.org/content/repositories/snapshots/ 45 | 46 | 47 | 48 | 49 | clojars 50 | Clojars repository 51 | https://clojars.org/repo 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TO BE DEPRECATED 2 | Clojure 1.12.x includes the add-libs function directly and the clojure.tools.deps.alpha library approach is deprecated. 3 | 4 | The approach used in this repository will still work for Clojure 1.11.x, although will eventually be replaced by a Clojure 1.12.x version. 5 | 6 | ![Clojure REPL driven development with hotload of libraries](https://raw.githubusercontent.com/practicalli/graphic-design/live/clojure/clojure-repl-hotload-libraries.png) 7 | 8 | ## REPL driven development with hot-loading of Libraries 9 | A simple web application server that is created using REPL driven development and hot-loading of libraries using `clojure.tools.deps.alpha` 10 | 11 | > NOTE: `clojure.tools.deps.alpha.repl/add-libs` design is not finalized and may change at any time without notice. If hot-loading stops working, check the [GitHub project](https://github.com/clojure/tools.deps.alpha) for changes. 12 | 13 | * [Project Repository](https://github.com/practicalli/hot-loading) 14 | 15 | 16 | ## Usage 17 | Start a REPL using the :repl/reloaded alias from [practicalli/clojure-deps-edn](http://practicalli.github.io/clojure/clojure-tools/install/community-tools.html) user-level configuration 18 | 19 | With Rebel Readline Terminal REPL UI with nREPL support: 20 | ```shell 21 | clojure -M:repl/reloaded 22 | ``` 23 | 24 | > Alternatively, use `:dev/reloaded` or `:lib/hotload` aliases with any `clojure` command to start a REPL 25 | 26 | Open the `src/practicalli/hot_loading.clj` file and evaluate each expression in turn that is contained within the `(comment ,,,)` rich commend block. 27 | 28 | Alternatively, [use the `deps.edn` project configuration file to hotload libraries](https://practicalli.github.io/clojure/alternative-tools/clojure-tools/hotload-libraries.html#using-add-libs-with-project-configuration-file). 29 | 30 | 31 | ## Use cases to explore 32 | 1) building a web application and wish to try different html generation libraries, hiccup and sablono. Hot load each of these libraries and try them out with the existing web application server. 33 | 34 | ## License 35 | Copyright © 2021 Practicalli 36 | 37 | Distributed under the Creative Commons Attribution Share-Alike 4.0 International 38 | -------------------------------------------------------------------------------- /src/practicalli/hot_loading.clj: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;; REPL driven development of a very simple Clojure webapp 3 | ;; 4 | ;; All the code has been written in side a rich comment block, 5 | ;; to be called by a developer using this code 6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 7 | 8 | (ns practicalli.hot-loading 9 | (:gen-class)) 10 | 11 | 12 | ;; Rich comment block with redefined vars ignored 13 | #_{:clj-kondo/ignore [:redefined-var]} 14 | (comment 15 | ;; run REPL with :alpha/hotload-libs alias 16 | (require '[clojure.tools.deps.alpha.repl :refer [add-libs]]) 17 | 18 | ;; hotload the libraries required for the server 19 | (add-libs 20 | '{http-kit/http-kit {:mvn/version "2.5.1"}}) 21 | ;; => (http-kit/http-kit) 22 | 23 | 24 | (require '[org.httpkit.server :as app-server]) 25 | 26 | 27 | ;; What functions are ava 28 | (ns-publics (find-ns 'org.httpkit.server)) 29 | 30 | ;; efine an entry point for the application 31 | (defn welcome-page 32 | [request] 33 | {:status 200 34 | :body "Welcome to the world of Clojure CLI hotloading" 35 | :headers {}}) 36 | 37 | ;; Start the application server 38 | (app-server/run-server #'welcome-page {:port (or (System/getenv "PORT") 8888)}) 39 | 40 | ;; Visit http://localhost:8888/ to see the welcome-page 41 | 42 | ;; Hotload Hiccup to generate html for the welcome page 43 | (add-libs '{hiccup/hiccup {:mvn/version "2.0.0-alpha2"}}) 44 | 45 | (require '[hiccup.core :as hiccup]) 46 | (require '[hiccup.page :as hiccup-page]) 47 | 48 | (defn page-template [content] 49 | (hiccup-page/html5 50 | {:lang "en"} 51 | [:head (hiccup-page/include-css "https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css")] 52 | [:body 53 | [:section {:class "hero is-info"} 54 | [:div {:class "hero-body"} 55 | [:div {:class "container"} 56 | [:h1 {:class "title"} (:title content) ] 57 | [:p {:class "subtitle"} (:sub-title content)]]]]])) 58 | 59 | ;; Check the page template returns HTML 60 | (page-template {:title "Hotload Libraries in the REPL" 61 | :sub-title "REPL driven development enables experimentation with designs"}) 62 | 63 | 64 | ;; redefine the welcome page to call the page template 65 | (defn welcome-page 66 | [request] 67 | {:status 200 68 | :body (page-template {:title "Hotload Libraries in the REPL" 69 | :sub-title "REPL driven development enables experimentation with designs"}) 70 | :headers {}}) 71 | 72 | 73 | 74 | ) ;; End of rich comment block 75 | --------------------------------------------------------------------------------