Fork me on GitHub
#shadow-cljs
<
2022-11-23
>
mhuebert08:11:55

> It is strongly recommended to use the standalone shadow-cljs version. The command does a lot of things to optimize the user experience (e.g. faster startup) which are not done by other tools. You’ll also save yourself a lot of headaches dealing with dependency conflicts and other related errors. is this still strong advice? just curious because I use deps.edn for almost everything these days and am wondering what I am missing out on. (I guess mainly fast startup? I haven’t experienced much in the way of dependency conflicts)

thheller08:11:55

this is talking about the shadow-cljs command specifically

thheller08:11:16

using deps.edn to manage dependencies but still running everything through the shadow-cljs command is fine

thheller08:11:41

so shadow-cljs watch app vs clj -M -m shadow.cljs.devtools.cli watch app

thheller08:11:46

the first is recommended, the second is not

thheller08:11:17

faster startup you only get by default when using shadow-cljs.edn as it defaults to using the AOT package by default

thheller08:11:33

deps.edn you can swtich thheller/shadow-cljs to thheller/shadow-cljs$aot to get the same

thheller08:11:16

dependency conflicts are more likely when using deps.edn but you can deal with that

thheller08:11:56

not quite accurate anymore since it doesn't AOT compile on demand but the reasons still apply

mhuebert08:11:49

ah ok that makes sense. thank you!

Leonid Riznyk08:11:03

Hello, I currently learning ClojureScript with Reagent and tailwind, and hot reload doesn't work. I run

npx shadow-cljs watch frontend
And when I save a file(views/app), changes don't affect the web page on reload And every time when I change something I need to restart the server to see the changes Here's my core.cljs
(ns frontend.core
  (:require [reagent.core :as r]
            [reagent.dom :as rdom]
            [frontend.views :as views]))

(defn ^:dev/after-load start
  []
  (rdom/render [views/app]
                      (.getElementById js/document "app")))

(defn ^:export main
  []
  (start))
How can I fix it?

thheller08:11:49

what does the browser console say?

Leonid Riznyk03:11:02

@U05224H0W Sorry for the such long response So, when I boot up shadow-cljs and open localhost in the web console writes this: shadow-cljs: #3 ready! and with every page reload number increases. And when I change anything in the code, nothing new happens

thheller06:11:04

then it doesn't seem to detect the file change properly?

thheller06:11:13

are you running in a container or something like that?

Leonid Riznyk06:11:27

No, I think not, sorry I am a complete noob in Clojure. I have just a simple shadow-cljs, reagent, and tailwind app without any additions

thheller06:11:32

not a clojure question. how do you run shadow-cljs? in docker or something like that? or the cloud? or just normally local in a terminal?

Leonid Riznyk06:11:08

No just local in terminal

thheller06:11:43

does it trigger a compilation message in the terminal?

Leonid Riznyk06:11:19

This is what terminal outputs:

thheller06:11:33

and nothing after changing and saving the file?

Leonid Riznyk07:11:50

No, nothing changes in terminal when i change a file

thheller07:11:29

hmm yeah then it doesn't detect the file changes

thheller07:11:55

not sure why it wouldn't though. everything seems to look correct. you sure you are editing the correct file?

thheller07:11:28

not a copy left in some wrong location or so?

Leonid Riznyk07:11:33

No, i'm edditing correct one, I even tried to edit same file where i have render function. (here, I editing "ui" component and rendering it, but nothing changes)

thheller07:11:20

hmm so the only explanation I have is that the file watcher doesn't work. which happens when running in containers such as docker. what kind of computer/os do you use?

Leonid Riznyk07:11:49

I using windows, and for terminal linux/oh-my-zsh

Leonid Riznyk07:11:27

may it can be because of IDE? I using intellij idea with Cursive

thheller07:11:30

do you run with wsl2? but access a file on the windows fs?

Leonid Riznyk07:11:16

yes as you said

thheller07:11:22

ok then thats the problem

thheller07:11:34

I use windows with wsl1 too

thheller07:11:53

I would recommend running shadow-cljs in windows then

thheller07:11:31

otherwise it only works if you run in wsl and also edit the files in wsl, ie. directly in /home/wherever

thheller07:11:39

not via /mnt/c/...

Leonid Riznyk07:11:52

Oh, i'll try that

thheller07:11:34

yeah file watchers in general don't work when using wsl1 but editing files from windows directly. nothing I can do about that unfortunately

Leonid Riznyk07:11:40

Yep, now everything is working, Thank you so much!

Leonid Riznyk07:11:03

didn't even thought that problem can be this)

thheller07:11:27

yeah wsl has some quirks

danielstockton15:11:00

Does anyone have any general tips for ensuring things that aren't needed are eliminated from the final compiled build? I'm looking at a build report and some of the things e.g. npm libraries are included when not needed (I have a couple of builds with different entry points, one needs these libraries and the other doesn't).

danielstockton15:11:17

For example, is it OK to 'exclude' npm libs using :js-options {:resolve when i know they're not needed by the build? Since the closure compiler/shadow doesn't exclude them via DCE

dvingo15:11:34

the other is putting those libs needed for dev in :preloads

danielstockton15:11:06

Aha, thanks @U051V5LLP very helpful

👍 1
danielstockton16:11:48

Still seems like the easiest thing is (if i know they will never be caled) is:

:js-options      {:resolve {"slate"         {:target :global :global "window"}
                               "slate-react"   {:target :global :global "window"}
                               "slate-history" {:target :global :global "window"}}}
With ns-aliases, I still have to define things within the noop ns

danielstockton16:11:24

"window" because target is browser and it won't error

dvingo16:11:03

aha, so you include these with <script> tags?

danielstockton16:11:05

That's what this resolve option is intended for, but in my case I know these dependencies are not needed by this build so I'm not including anything.

dvingo16:11:48

ah interesting

danielstockton16:11:56

The compiler can't deduce that they aren't needed, since they're npm libraries.

dvingo16:11:56

I guess the usual solution is to not include the namespaces in the release build somehow (preloads are one way) but I don't know the requirements/constraints of your app, so this seems like a good solution

dvingo16:11:57

the other way I've gone about this is having a dev namespace for a file and a release version still using ns-aliases e.g. https://github.com/matterandvoid-space/todomvc-fulcro-subscriptions/blob/766d27be316c3f2ab6a23bd8db30932ec0601a4f/shadow-cljs.edn#L11

dvingo16:11:14

in the release file you would not include those npm modules in the :ns form

dvingo16:11:21

but your version seems like less busy work

danielstockton16:11:09

Right yeah, it's probably also the case that my namespaces could be better organized to make some of this easier.

danielstockton16:11:16

i.e. i am using parts of this namespace, but not others. Maybe i can better separate them by build.

dvingo16:11:05

ah gotcha. yea probably sounds like it. But if it works, then oh well 🙂 thanks for sharing the solution btw - learned a new trick

thheller21:11:36

@U0DHDNZR9 you can just :resolve {"slate" false} to not include it at all, but yeah its better to organize the namespaces in a way they don't get included in the first place

danielstockton22:11:58

Even better, thanks!