Hello Clojureverse! I’m wondering what the current best way is to start a new cljs project that uses reagent. Imagine someone coming from non-clojure world who’s used to running some-cli new project then some-cli dev and getting started right away with app development, no faffing with config/build tools etc.
What’s the closest we have to that right now for a new reagent app?
For context, I’ve been working with Clojure for the past ~2 years, but almost all JVM Clojure and want try making some little web apps with cljs and my front-end experience is all with batteries-included clis (for React and Angular) and I was wondering if there’s anything similar for cljs. Manually editing config files makes me hate programming. I’m comfortable editing json/edn and have done it for work before, but I would love my life more if I didn’t have to. So: is there some way I can just run a command to build a skeleton reagent app to start customizing in 1 minute?
Hi,
this worked pretty well for me: “lein new luminus my_project +reagent”
It’ll give you a nice directory structure and include necessary dependencies for both backend and frontend. Importantly, it will give you an ajax.cljs file that you can use to interact with backend from frontend. Perhaps you’d like to separate backend and frontend. I haven’t, but seeing what that command generates gives me clear ideas on how I can separate them.
If you use this command, running app at dev time with “lein figwheel” may not completely work. You will need to run both “lein run” and “lein figwheel” in separate terminals. Your run will listen on port 3000 and figwheel on 3449. I did not have any other problems.
you‘ll need clojurescript and reagent as dependencies, so either project.clj or shadow-cljs.edn
That’s basically it, the shadow-cljs user guide pretty much has the details all written out. Once you‘ve done the setup a few times it will be approaching a couple of minutes of setup time going a somewhat manual way (again personal preference).
To my knowledge, there’s no create-react-app for all the different kinds of ways you could set it up for a Clojure/Script environment in one command - and I have the feeling you wouldn’t want to
Edit: I share your distaste of config files; I‘ve had my fair share of bouts with the various webpack arcana required for the different major versions over the years. It’s a bit different with ClojureScript tooling, since although you still do have to tell it some of the stuff going on in your project, it’s very stable and usually you don’t need to touch it a lot (at least not in a „new webpack is out, time to rewrite and debug 1500 lines of config script“ kind of way)
This is pretty close to what I did. You’re totally right that it’s not nearly as a big a deal to maintain a small shadow-cljs.edn config as it is to deal with the nightmare world of webpack etc. And I appreciate and understand why the Clojure world isn’t big on batteries-included solutions, but it does make the getting started experience feel extremely janky and dysfunctional by modern web development standards. I worry it’s a barrier for a lot more people than we think.
You can now use npx create-reagent-app my-project to get up and running in less than a minute, in the same way as you might use npx create-react-app my-project in JavaScript land.