Can I write frontend (reagent) and backend (express.js) applications in a same clojurescript project?
Following these two pages.
Writing Node.js applications in Clojure and using NPM packages Backend (express.js)
shadow-cljs Frontend (reagent, react)
Both of them are similar, create a new cljs project with npx create-cljs-project {project-name}
. However, these are two individual projects, can I write frontend and backend application in a same project, if it is possible, how to manage repl in this project?
Sure, the entire system is designed to combine as many things as you like. Just configure multiple builds in the
shadow-cljs.edn
:builds
map.If you already have both separate projects just take the .cljs files and move them to the other. Then take the build config and also move it into the other
shadow-cljs.edn
.You may either control multiple builds from the shadow-cljs UI or the command line. All build relevant commands allow you to specify multiple builds (eg.
npx shadow-cljs watch backend frontend
, with the:frontend
and:backend
builds inshadow-cljs.edn
).You can use namespaces to properly "categorize" your project. I generally have something like
my.app.ui
ormy.app.frontend
for frontend related things and something likemy.app.server
ormy.app.backend
.With the
watch
for both builds running you can just switch between the REPLs in your editor. From the command line you can justnpx shadow-cljs cljs-repl frontend
ornpx shadow-cljs cljs-repl backend
. Or switch between them from a Clojure REPL vianpx shadow-cljs clj-repl
and then(shadow/repl :frontend)
. That'll bring you into the CLJS REPL for the:frontend
build. You may exit that via:cljs/quit
, which brings you back to the CLJ REPL.