What is the current best way to start a new clojurescript project?

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?

2 Likes

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.

Hope this helps

1 Like

and, yes, seems like I forgot to mention… you can also just run:
lein new reagent-figwheel my-project

but this includes less scaffolding

It‘s probably not a minute if you‘ve never done it before, but it’s about the time it takes me currently to set this up.

I recommend shadow-cljs and leiningen for a very quick start and easy integration in e.g. Cursive:

  • run lein new ... or get a project set up any way you like (an essential setup is just a project.clj and a source file)
  • cd into project; run npm init and set up the npm part
  • run npm install -D shadow-cljs react react-dom and leave npm land
  • add a shadow-cljs.edn and configure what you need as per the user guide (https://shadow-cljs.github.io/docs/UsersGuide.html#Leiningen) - I‘d let leiningen handle dependencies, no particular reason except it’s been working smoothly for me
  • 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)

1 Like

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.

2 Likes

In addition to the other examples in this thread, here are a few more projects in a similar spirit:

1 Like

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.

1 Like

I just created a bare bones Firebase cljs demo GitHub - henryw374/firerebase-clojurescript-crud: tutorial on setting up a simple crud add with clojurescript and firebase - I’m planning to add some more stuff but feedback welcome!

3 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.