Skip to content

Commit 1f763f8

Browse files
FiV0bbatsov
authored andcommitted
[Docs] shadow-cljs with deps.edn and custom repl init
1 parent 3168f93 commit 1f763f8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

doc/modules/ROOT/pages/cljs/shadow-cljs.adoc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,48 @@ If you already have a running server watching a build (for instance
7070
you have already run `npx shadow-cljs watch :dev`), you can use the
7171
`shadow-select` CLJS REPL and specify `:dev` when prompted.
7272

73+
=== Using shadow-cljs with deps.edn and custom repl initialization
74+
75+
In case you want to manage your dependencies via https://clojure.org/guides/deps_and_cli[deps.edn], you can use a
76+
custom cljs-repl init form. This supposes you have shadow-cljs in your `deps.edn` dependencies.
77+
```clj
78+
{:paths ["src"]
79+
:deps {...
80+
thheller/shadow-cljs {:mvn/version "2.15.6"}
81+
...
82+
}
83+
:aliases {:dev {:extra-paths ["dev"]}}}
84+
```
85+
86+
Create a `:dev` alias with an extra source path of "dev" and add the following namespace
87+
```clj
88+
(ns user
89+
(:require [shadow.cljs.devtools.api :as shadow]
90+
[shadow.cljs.devtools.server :as server]))
91+
92+
(defn cljs-repl
93+
"Connects to a given build-id. Defaults to `:app`."
94+
([]
95+
(cljs-repl :app))
96+
([build-id]
97+
(server/start!)
98+
(shadow/watch build-id)
99+
(shadow/nrepl-select build-id)))
100+
```
101+
102+
Supposing your build-id is `:app`, add the following to your `.dir-locals.el`
103+
```elisp
104+
((nil . ((cider-clojure-cli-global-options . "-A:dev")
105+
(cider-preferred-build-tool . clojure-cli)
106+
(cider-default-cljs-repl . custom)
107+
(cider-custom-cljs-repl-init-form . "(do (user/cljs-repl))")
108+
(eval . (progn
109+
(make-variable-buffer-local 'cider-jack-in-nrepl-middlewares)
110+
(add-to-list 'cider-jack-in-nrepl-middlewares "shadow.cljs.devtools.server.nrepl/middleware"))))))
111+
```
112+
113+
`cider-jack-in-cljs` should then work out of the box.
114+
73115
== Configuration
74116

75117
You can tweak the command used by `cider-jack-in-cljs` to start the `shadow-cljs` server

0 commit comments

Comments
 (0)