Fork me on GitHub
#shadow-cljs
<
2019-02-23
>
Pavel Klavík16:02:59

hi, I am trying to get shadow-cljs running with luminus template with +cljs, but I cannot get it working

thheller16:02:25

what is the problem?

Pavel Klavík16:02:15

I generated the following shadow-cljs.edn:

{:source-paths ["src/cljs"]
 :dependencies [[binaryage/devtools "0.9.10"]]
 :nrepl        {:port 9000}
 :builds       {:app {:target           :browser
                      :output-dir       "target/cljsbuild/public/js"
                      :asset-path       "/js/main.js"
                      :modules          {:main {:init-fn exp.core/init!}}
                      :compiler-options {:infer-externs :auto}
                      :devtools         {:http-root    "public"
                                         :http-port    3449
                                         :http-handler shadow.http.push-state/handle
                                         :after-load   exp.core/mount-components}}}}

Pavel Klavík16:02:11

but I get errors that js files in subdirectories are not found: http://localhost:3000/js/main.js/cljs-runtime/goog.debug.error.js net::ERR_ABORTED 404 (Not Found)

thheller16:02:14

:asset-path "/js/main.js" is wrong

thheller16:02:30

:asset-path "/js"

Pavel Klavík16:02:49

ok, that makes sense 🙂

thheller16:02:50

the files will be put into :output-dir as <module-id>.js, so main.js in your case

Pavel Klavík16:02:07

cool, it seems to work now, thanks

Pavel Klavík16:02:15

how does the hot code reloading work in this case? I understand that shadow-cljs runs its own server on port 3449 which connects to the browser via websockets and updates the website with exp.core/mount-components when the source files are updated.

Pavel Klavík16:02:30

but in this case, the server runs on port 3000, so how does shadow-cljs update it?

thheller16:02:48

shadow-cljs runs a server in 9630 that handles the live reload

thheller16:02:05

the one you started on 3449 is just a completely static webserver for serving files

thheller16:02:15

which you don't need if you have the files served on 3000

Pavel Klavík16:02:56

I see, so basically as files are served from 3000, they contain in development information that they should connect to 9630 and listen for updates there?

Pavel Klavík16:02:45

cool, might be useful to explain this somewhere in shadow-cljs user guide (or maybe it already is explained there), because I found that quite puzzling

Pavel Klavík16:02:17

thx, makes sense now, when I understand everything better, but still little bit difficult for beginners to understand. In the future, I might write some beginners tutorial about all these things.