Calva supports most any JVM hosted ClojureScript environment (and some others, including SCI based, too), but shadow-cljs gets some special treatment to try make it extra convenient to use.
With many shadow-cljs projects, Calva's connect project type shadow-cljs, is the right choice. Projects that use Leiningen or deps.edn can be used both with the Leiningen/deps.edn and shadow-cljs type, depending on configuration see below for more on this.
shadow-cljs - browser quickstart#
Here's how you start a shadow-cljs ClojureScript REPL and connect Calva with the shadow-cljs - browser quickstart example project:
Prep:
- Clone the project to your machine and open its root folder in VS Code.
- Open a terminal and run
npm install
Connect Calva:
- Run the command Calva: Start a Project REPL and Connect (a.k.a. Jack-in)
- Select project type shadow-cljs
- Select to start the build :app
- Select to connect to the build :app
- Wait for the build to complete
- Open http://localhost:8020/ in the browser
- Open browser.cljs file and load it in the REPL: Calva: Load/Evaluate Current File and Dependencies
Now you can should be able to evaluate forms, e.g.:
- The current form or selection with ctrl+enter, or
- Top-level forms with alt/option+enter.
(See Code Evaluation)
shadow-cljs in full stack projects#
shadow-cljs is a bit special in regards to Calva REPL connection. Mainly because you can start shadow-cljs and it's nREPL server in two ways:
- Using the shadow-cljs npm executable
- Via the Clojure REPL in your Leiningen or deps.edn project
These options show up as project types when connecting or jacking in:
- Project type: shadow-cljs
- Project type: deps.edn + shadow-cljs or Leiningen + shadow-cljs
The technical difference here is wether you let shadow-cljs start clojure/Leiningen (the first option) or if you let Calva do it (the second option). If you let Calva do it, Calva will then start the shadow-cljs watcher from the Clojure process. From a usage perspective the two approaches will result in different channeling of shadow-cljs output, e.g. test runner results. With the first option (the shadow-cljs project type), shadow-cljs output will be channeled to the Jack-in terminal. With the deps.edn/Leiningen option, that output will be channeled to the Output/REPL window.
See shadow-cljs + Clojure with Calva: The basics for some more discussion on how the REPL connection works.
shadow-cljs and clojure
aliases
The shadow-cljs project type will not prompt you for any aliases found in the deps.edn
file. Usually you should provide such aliases in shadow-cljs.edn
like :deps {:aliases [...]}
. If, for whatever reason you can't provide the aliases that way, you can configure a Custom REPL Connect Sequence and provide the aliases as menuSelections
-> cljAliases
.
Leiningen + shadow-cljs middleware issue
Please note that for Leiningen, the command line dependency injection of the shadow-cljs nrepl middleware doesn't work. You need to add it to your project.clj
:
:repl-options {:nrepl-middleware [shadow.cljs.devtools.server.nrepl/middleware]}