shadow-cljs in CIDER

2021-04-26

<prev next>

I've been working on a Clojure served Clojurescript web-app thing.

I'd like to have a Clojure server and Clojurescript frontend, using shadow-cljs to rebuild and hot load the Clojurescript. I'd also like to get REPLs on both the server and frontent. I had something like this working with Figwheel, but it would be nice to have everything running in one process so I can leave CORS alone (since I want everything to be same domain at the end of the day and I'd like dev and deployment to look as much the same as possible).

I started typing up My Life Story and How I got Here, but it's not that interesting, so I'll leave it at this: I couldn't find these pointers on the internet so now I'm typing them up for you (most likely me at a later date).

Shadow-cljs is a library, and you can run watch and compile by calling a couple functions. The docs cover several use cases, which are not relivant here, all you need to do is load your REPL and run (shadow.cljs.devtools.server/start!) and (shadow.cljs.devtools.api/watch :my-build) where :my-build is one of the :builds in your shadow-cljs.edn.

Ok. Look at the output, it'll show your nREPL port. Connect that (in my case, M-x cider-connect-cljs localhost\n1234\nshadow\n, but follow your prompts).

That's about it. Start your server, load your page. Remove the :dev-http configuration from your shadow-cljs.edn.

Q: Couldn't you do this with Figwheel? A: I don't know. Probably?

Q: Isnt' the CORS thing with figwheel-main pretty straight forward? A: I guess – there's a ring.middleware.cors/wrap-cors middleware which makes it easy to accept requests from the figwheel address (it looks like I set it to localhost:9500, which is the figwheel-main default I think).

[Update 2021-04-27] Well, I still don't understand what's going on. Everything was working last night but when I picked up today hot-reload broke on the page served from my backend and the :dev-http page has the expected CORS issues.

If I mess with the fulcto-http-remote :url parameter things break, but when I remove it (i.e. revert to how I started today) everything starts works on the backend hosted page.

I guess something is caching something and I've run into one of the two famous problems in CS.

Things seem to be working again now. If I have any trouble tomorrow I'll start by nuking the compiled JS, and apparently "Control+r" will used cached data, so I'll start using "Control+Shift+r" tomorrow.

If that doesn't work, I'll try something else and maybe update this blog again.