shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
isak 2021-03-12T20:37:15.384300Z

Is there a good way to develop shadow-cljs locally and use in other projects? Like lein install, except if you want to use it the recommended way (npm)?

thheller 2021-03-12T20:41:14.384500Z

I just lein install

1
thheller 2021-03-12T20:41:42.385Z

the recommended way still just uses the installed version in .m2 so that has nothing to do with it

1
thheller 2021-03-12T20:42:14.385500Z

what do you intend to do? another way is just putting the shadow-cljs src/main into the source paths of your project

thheller 2021-03-13T08:32:02.413600Z

if you intend on working on it while working on a project I'd definitely recommend just adding the source path to the project

thheller 2021-03-13T08:32:48.413800Z

I do this frequently. all projects in ~/code so just :source-paths ["src/main" "../shadow-cljs/src/main"]. while keeping the normal shadow-cljs dependency to get all other transitive dependencies and stuff

thheller 2021-03-13T08:33:55.414100Z

works fine with project.clj or deps.edn as well

isak 2021-03-13T22:40:42.435Z

I'll give that a shot, thanks!

Jason 2021-03-12T21:22:11.392900Z

I'm playing with monorepo multiproject multibuild settings and I'm getting a fresh error. I'm not sure where I went wrong with deps.edn alias:

:dev-cljs
  {:extra-deps {thheller/shadow-cljs          {:mvn/version "2.11.22"}
   ...
   :main-opts  ["-m" "shadow.cljs.devtools.cli" "watch" "ui"]}
and shadow-cljs.ednbuild:
{:ui {:target :browser
       :output-dir "projects/ui/public/js"
       :asset-path "projects/ui/js"
       :module-hash-names false
       :modules {:ui {:init-fn ui.main/init!
                      :preloads [devtools.preload
                                 day8.re-frame-10x.preload]}}
       :dev {:compiler-options {:infer-externs :auto
                                :closure-defines
                                {re-frame.trace.trace-enabled? true
                                 day8.re-frame.tracing.trace-enabled? true}}}
       :devtools {:repl-pprint true
                  :preloads [shadow.remote.runtime.cljs.browser]
                  :http-root "projects/ui/public"
                  :http-port 8280}}}
When i load the app in the browser, I get "is the watch for this app running?". I only changed paths to move the location of shadow-cljs.edn up a couple of directories. Any help appreciated.

thheller 2021-03-12T21:46:34.393500Z

@jasonhlogic first of all your :asset-path looks incorrect. likely that should just be /js?

thheller 2021-03-12T21:46:58.394100Z

the error you get is when the files you are loading were not produced by the running shadow-cljs instance

thheller 2021-03-12T21:47:23.394700Z

so likely if you changed some paths or so you have some older files still somewhere that are not used instead of the new output

thheller 2021-03-12T21:49:29.395300Z

or you jsut haven't started the watch? don't know which command you run

Jason 2021-03-12T21:56:18.399200Z

I changed the :assset-pathto "/js", but I still get the same error. My command is:

clojure -M:defaults:ui:dev-cljs
where defaultsis a set of override-deps to version-lock libraries shared across projects and ui is:
{:extra-deps {ui/ui {:local/root "projects/ui"}}}
which adds the project-level deps.edn

thheller 2021-03-12T21:56:54.399500Z

not a clue how that works but it doesn't matter for shadow-cljs

thheller 2021-03-12T21:57:05.399800Z

you are opening http://localhost:8280 I presume?

thheller 2021-03-12T21:57:48.400600Z

that serves the files from <project>/projects/ui/public

Jason 2021-03-12T21:57:53.400800Z

Confirmed.

Jason 2021-03-12T21:58:21.401400Z

Also correct.

thheller 2021-03-12T21:58:23.401500Z

and you are including <script src="/js/ui.js"> in the HTML

thheller 2021-03-12T21:58:52.402300Z

do you maybe have two instances of shadow-cljs running?

Jason 2021-03-12T21:59:34.402800Z

Yes, this app ran before I changed the paths

thheller 2021-03-12T22:00:19.403700Z

simple test. shutdown shadow-cljs and open the http://localhost:8280

thheller 2021-03-12T22:00:35.404300Z

if you still get a reply then find out from where

Jason 2021-03-12T22:00:35.404400Z

Only one instance running, and these resuts are confirmed by another developer

thheller 2021-03-12T22:00:57.404600Z

could be a service worker if you have one

Jason 2021-03-12T22:01:41.405800Z

I shut down the instance and the browser says it can't connect

thheller 2021-03-12T22:02:24.406200Z

ok

thheller 2021-03-12T22:03:42.407Z

then I'm out of ideas. there really isn't much that goes into this. shadow-cljs places the files in the :output-dir and the :http-root serves them

thheller 2021-03-12T22:03:55.407400Z

but especially if you move some files or change directory names or so

thheller 2021-03-12T22:04:13.407800Z

it is easy to miss one place and is still using an old file from some other directory

Jason 2021-03-12T22:04:41.408200Z

yes, let me go clean those out.

thheller 2021-03-12T22:06:03.408700Z

you can also remove :preloads [shadow.remote.runtime.cljs.browser]. that has been the default for a while now.

thheller 2021-03-12T22:06:13.409Z

but that doesn't affect anything regarding this

Jason 2021-03-12T22:07:20.409900Z

happy to clean out old opts 🙂

Jason 2021-03-12T22:15:17.412200Z

i found it. i changed the build name to 'ui' but did not update the name of the js file the index page loads. Thank you very much for your responses. I'm sorry to have taken your time with my config error.

thheller 2021-03-12T22:15:53.412500Z

the build name doesn't affect this. the :modules key does.

Jason 2021-03-12T22:18:53.412900Z

duly noted and thanks again