(when in VS code, press ctrl-k v
to render this file)
This project shows several things:
- Hot CSS reloading
- Hot code reloading (compile-on-save, no browser reload required)
- RPC mechanism for bidirectional websocket to back-end
- sample querying of CouchDB via REST interface
- initialized GIT repository
- one language for client (browser) and server code
- extremely low complexity (the Abstract Syntax Tree of the code contains just under 210 nodes!)
- extremely small project size (±395 lines of code and project files, not counting README)
- package entire project into 1 file (.jar) to run everywhere
- backend is JVM with a web-server and server-side code
- front-end code is compiled to javascript and delivered via JVM web-server
- JS code size while developing: less than 5MB
- JS code size after compiling for production: ±630KB (less than 165KB gzipped)
- segmented state map using lenses (reduces events and facilitates refactoring)
- paginated DB access
- have a linux system ready, or find out the rest by yourself :)
- install
clj
from http://clojure.org/ - make sure you have git installed
- have Visual Studio Code installed to follow this document precisely
- run VS code and install
calva
plugin, no config required - open this project (obviously)
- open your standard browser first
- then start project with
ctrl-alt-c ctrl-alt-j
- select
deps.edn + Figwheel-main
, then:fig
option in next dialogue
9a. the running browser will show the app - change browser URL from port 9500 to 8000; nothing will show up
- open
src/clj/mkproj-demo/core.clj
and click in window - press
ctrl-alt-c enter
to compile namespace - type in (in CLJ REPL):
(-main)
- refresh browser
- any changes you save lead to immediate changes in the browser
- install CouchDB
- make database named
sample
- create document with fields "type": "person", "name": "Jack", "age": 21
- create index (for sorting) on "name"
- enable CORS in settings
- use [yourhost] instead of localhost in browser from now on
- close VS code
- in project directory run
clj -Moptimal
- delete extraneous files:
rm -rf target/public/cljs-out/dev
- generate pom.xml with
clj -Spom
- package with
clj -Xuberjar
- run with
java -jar target/mkproj-demo.jar
- open browser to http://[yourhost]:8000/
If you move the jar file, keep in mind that all paths are relative to the location from where you run, i.e. if the code opening data/items.edn
is still there, you'll get an error.
Run clj -Moutdated
from the project directory.
A table of suggested updates (to be put in deps.edn) might be shown.
Lightweight intro:
http://maria.cloud/
http://clojure.org/
http://clojurescript.org/
http://hoplon.io/
https://github.com/jarohen/chord
©2022 Roel Pompen