Skip to content

Commit 96f9e3d

Browse files
committed
introduce a CLJS setup for client-side scripting
replacing HTMX+hyperscript
1 parent 65974cd commit 96f9e3d

9 files changed

Lines changed: 2006 additions & 51 deletions

File tree

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
.clj-kondo/
1111
.lsp/
1212
.portal/
13+
.idea/
14+
.shadow-cljs/
15+
*.iml
16+
node_modules
17+
resources/public/css
18+
resources/public/js

‎README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,28 @@ To start the app:
1010
1. Create a new `secrets.env` file
1111
2. Run `bb generate-secrets` and paste the output into `secrets.env`
1212
3. Run `bb dev`
13+
4. Open a second terminal, run `npm install`
14+
5. Run `npx shadow-cljs watch client` during development or `npx shadow-cljs release client` for a production build.
15+
16+
17+
18+
## CLJS Notes
19+
20+
### Disclaimer
21+
22+
I'm not actually familiar with `biff`, I only did minimal changes to the code. I did not attempt to integrate `shadow-cljs` into the facilities `biff` provides. I actually prefer to run things separately, but I'd assume it is totally possible to integrate all this more smoothly. I also didn't figure out why the Websockets never receive any messages, or why creating a secondary user can't see what the first created. The HTMX variant had the same issue, and I didn't investigate further.
23+
24+
### Steps taken
25+
26+
- I ran `npm init -y` to create a `package.json`
27+
- I ran `npm install tailwindcss shadow-cljs` (the tailwind install `bb dev` tried to make didn't work on my machine, so I ran `tailwindcss` manually to get the CSS)
28+
- I created the `shadow-cljs.edn` file and added the `:client` build.
29+
- Added the `:client` alias and required dependencies to `deps.edn`
30+
- I removed HTMX and all references to it
31+
- The newly introduced `com.eelchat.client` namespace replaces that functionality.
32+
- Included the generated `/js/main.js` script.
33+
34+
Note, for purists, the entire npm thing is **optional**.
35+
36+
You can run this entirely only with `clj` and never even install or touch `node/npm`. I opted to use it because I don't mind. Basically the only thing you'd change is running `clj -A:client -M -m shadow.cljs.devtools.cli watch app` instead of `npx shadow-cljs watch app`. Same for `release`.
37+

‎deps.edn‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44
remus/remus {:mvn/version "0.2.2"}
55
org.jsoup/jsoup {:mvn/version "1.11.3"}
66
org.clojure/clojure {:mvn/version "1.11.1"}
7-
org.slf4j/slf4j-simple {:mvn/version "2.0.0-alpha5"}}}
7+
org.slf4j/slf4j-simple {:mvn/version "2.0.0-alpha5"}}
8+
9+
;; I'd generally recommend moving the server only deps above into their own alias
10+
;; but I don't know how to make "bb dev" use that alias
11+
;; we don't need them for CLJS compilation, and they might cause conflicts
12+
;; works fine for this demo though
13+
:aliases
14+
{:client
15+
{:extra-deps
16+
{com.thheller/shadow-graft {:mvn/version "0.9.0"}
17+
thheller/shadow-cljs {:mvn/version "2.24.1"}}}}}

0 commit comments

Comments
 (0)