This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-27
Channels
- # announcements (16)
- # architecture (19)
- # beginners (31)
- # calva (2)
- # cider (1)
- # clerk (4)
- # clj-yaml (58)
- # cljdoc (2)
- # cljs-dev (10)
- # clojure (77)
- # clojure-europe (108)
- # clojure-norway (26)
- # clojure-sanfrancisco (2)
- # conjure (1)
- # cursive (2)
- # datahike (5)
- # datomic (13)
- # emacs (7)
- # etaoin (3)
- # hyperfiddle (15)
- # introduce-yourself (3)
- # kaocha (1)
- # off-topic (21)
- # reagent (4)
- # releases (1)
- # shadow-cljs (41)
- # spacemacs (28)
- # specter (8)
- # squint (30)
- # yamlscript (2)
Is there a way to use squint within a server-side clojure web app that is generating hiccup and wants to add a splash of javascript? I'm currently using scriptjure's js
macro but it has bugs and a lot of limitations. Would be amazing to use squint instead.
Ive seen example somewhere. Require squint in file with hiccup. Slurp cljs code to string, and pass it squint complile fn. Place resulting js string value in script tag in page hiccup.
Cool! My 2c: this is a killer use case and would warrant an example on the squint README. I wasn't sure if squint was even possible to run in JVM/clojure land.
here is the example with cherry, but squint should work similarly: https://twitter.com/borkdude/status/1555947698578198532
Oh fascinating, yeah this is exactly what I'm looking for. Interesting es-module voodoo I had not seen before. Can't wait to try this out when I'm at my computer later today, will report back. Thank you!
The es module shim might not be necessary anymore, import-maps should be available anywhere now, but back when I tried it, Safari gave some problem
Here are some related squint examples: https://github.com/babashka/nbb/blob/main/examples/squint/example.cljs https://www.reddit.com/r/Clojure/comments/ydqvfd/comment/ittvcu9/
$ clj -Sdeps '{:deps {io.github.squint-cljs/squint {:git/sha "7759ebc409e97d8b67a9ca3cabcfd83d2fcb2d33"}}}'
Clojure 1.11.0-alpha4
user=> (require '[squint.compiler :as sq])
nil
user=> (sq/compile-string "(defn foo [] (+ 1 2 3))")
"var foo = function () {\nreturn (1 + 2 + 3);\n}\n;\n\nexport { foo }\n"
`Update: working beautifully, no shim necessary at least on my versions of firefox/safari. Here's a public example repo which you're free to link to from the squint docs if you think it'd be worthwhile: https://github.com/aiba/squint-hiccup-example/blob/master/src/squint_hiccup_example/core.clj
My only remaining question is whether I should be using squint or cherry for my use case. Originally I thought squint would be more lightweight, but it looks like the required core library is about the same size as cherry's, so I wonder if I might as well be using cherry? Curious if you have a thought on this.
OK, I'm happy with this example, I think it's tweetable if you're so inclined: https://github.com/aiba/squint-hiccup-example/ (though open to feedback if you think it could use more explanation or any changes!)
This got a lot easier now: https://github.com/squint-cljs/squint#compile-on-a-server-use-in-a-browser
An example of calling squint from a JVM server process and generating JS on the fly in the response: https://github.com/aiba/squint-hiccup-example/ - thanks @aiba!
Very cool, thanks! Haven't thought about compiling the code like that.