Fork me on GitHub
#shadow-cljs
<
2021-06-10
>
tlonist05:06:56

How do I update new dependencies in shadow-cljs?

tlonist05:06:53

I added a new dependency in shadow-cljs.edn, (by the way I’m using intellij + cursive) and re-ran shadow-cljs watch app. But my cljs file still cannot find required libraries in the namespace.

tlonist05:06:06

I’ve done pom.xml-> download sources as well.

Aron05:06:11

I just restart shadow-cljs

tlonist05:06:25

shouldn’t

shadow-cljs watch app 
do?

thheller06:06:36

if its already running no, you need to restart it fully. shadow-cljs stop should shut it down completely

thheller06:06:58

also depends on how you have configured shadow-cljs.edn. if you have a :deps key in there then dependencies need to be added in deps.edn. if there is a :lein then it would be project.clj.

tlonist06:06:12

Thanks! I ran

shadow-cljs pom
and re-imported the project in ide, which worked out.

thheller06:06:54

ah, thought you meant shadow-cljs didn't find dependencies. yeah shadow-cljs pom to make the dependencies visible for Cursive

👍 3
🙏 3
Michaël Salihi09:06:51

Hi! I'm interested in how to manage the versions of the JS bundle. I have read the part of the documentation https://shadow-cljs.github.io/docs/UsersGuide.html#_cacheable_output and knowing that my html is generated by hiccup, I am thinking of using the solution from the manifest.edn file. Are there some leads? How do you do with Shadow-cljs when an index.html file is used to call the script?

thheller10:06:02

but if you have hiccup you don't need to hook

thheller10:06:13

just read the manifest.edn and generate the script tag from that?

thheller10:06:40

slurp -> edn/read-string and transform it however you need. its just clojure data.

Michaël Salihi10:06:53

> slurp -> edn/read-string and transform it however you need. its just clojure data. Perfect, that's what I'm putting together. Thank you for confirming that I am going in the right direction.

Michaël Salihi10:06:15

I was not aware of this hook, it's wonderful! Thank you

Michaël Salihi10:06:03

@thheller Shadow-cljs is full of hidden gems ... I never regret when I ask questions! 🙂

😎 2
👆 2
Michaël Salihi13:06:34

Another question. If I doesn't the built-in Shadow server and want to watch/reload the CSS file locate in resources/public/css/app.css, what path do I put in {:devtools {:watch-dir "???"}} option?

Michaël Salihi13:06:58

The path must be in the classpath too?

Michaël Salihi13:06:23

I tried multiple solution but no success.

thheller13:06:24

resources/public assuming the file is accessed via /css/app.css in your html

Michaël Salihi13:06:28

Yes, this is the case.

Michaël Salihi13:06:51

Strange, I already try with this path but no success.

thheller13:06:56

you need to restart the watch for this to take effect

Michaël Salihi13:06:40

Oh ok, I try to restart

Michaël Salihi13:06:20

After restarting, I touch resources/public/css/app.css but not rebuild happened

thheller13:06:44

what rebuild do you expect? css is not built by shadow?

Michaël Salihi13:06:34

Yes I know I am using postcss for this. I meant reload

thheller13:06:03

I don't know. what is the EXACT html link tag you use to include it?

thheller13:06:30

and I'm assuming resources/public/css/app.css is the OUTPUT file produced by postcss, not the input?

Michaël Salihi13:06:47

Yes the output file.

Michaël Salihi13:06:51

<link href="/css/app.css" rel="stylesheet" type="text/css">

thheller13:06:46

and your webserver doesn't cache the file or so? I mean what do you see in the browser console? shadow-cljs should be telling you what it is doing

Michaël Salihi13:06:15

I just got it. My public folder does not contain an index.html file as this is handled by hiccup. I thind watch-dir works only with html file, right?

thheller13:06:25

no, doesn't care

Michaël Salihi13:06:58

OK, good to know

Michaël Salihi13:06:20

> and your webserver doesn't cache the file or so? I mean what do you see in the browser console? shadow-cljs should be telling you what it is doing I'll do some tests and I'll tell you

thheller13:06:38

there really isn't much to this. :watch-dir will cause shadow to watch that directory and notify about file updates. the client will look for CSS matches by path and reload if found

thheller13:06:19

again ... look at the console. if you see a load CSS message from shadow-cljs but css didn't update then your server likely caches stuff and didn't return the "new" version

thheller13:06:32

if no load CSS shows up then it didn't match the paths properly

Michaël Salihi13:06:37

Load CSS shows up and CSS reload now, perfect!

Michaël Salihi13:06:36

I think my various tests without restarting shadow-cljs watch misled me. A big thank you again!

Michaël Salihi14:06:04

More I works with Shadow-CLJS and more I'm impressed by the nice piece of librarie that it is! 😉

❤️ 2
knubie15:06:45

I’ve got a function in my app (defn my-fn [x] (do-stuff-with-x)) that gets sent the method toString by some library code. How can I guarantee that toString returns the same value for every build? (I think toString is returning different values because advanced compilation is renaming the function).

thheller15:06:09

I don't understand. "gets sent the method toString by some library code.". what does that mean?

thheller15:06:14

you mean you are calling toString on a function?

knubie16:06:28

sometimes in OOP calling a method is also called “sending a message”

knubie16:06:10

so it looks like myFn.toString()

knubie16:06:41

For some context, the pouchdb library does this to create a unique replication ID

knubie16:06:52

it takes the stringified function, plus some other options to create the unique ID

knubie16:06:22

and if the ID change, it will sync everything (which I’m trying to avoid)

thheller16:06:07

why does it take a stringified function? that sounds like total nonsense?

thheller16:06:16

but there is no way to guarantee that the function will always stay the same with :advanced, at least as far as I'm aware

thheller16:06:04

why can you not choose which string to use? why a stringified function? I don't get it. have some docs?

knubie16:06:50

I believe the idea is that you would want to re-start replication from scratch if any of the parameters for the replication changes

knubie16:06:16

what if I import the function from a javascript module?

thheller16:06:24

and where is that function used? everything going through :advanced or even :simple is never guaranteed to stay identical

knubie16:06:32

I could fork the library (I already maintain a fork of this lib so it wouldn’t be a huge deal)

thheller16:06:41

hmm yeah no clue, I don't see a way to keep this totally stable

thheller16:06:44

I mean any kind of minifier should have this issue? it might end up sort of stable but there is no guarantee

knubie16:06:34

Yeah seems like that would be the case

knubie16:06:46

I’ll search around the issues and stuff to see if anyone else has the same problem

knubie16:06:50

thanks for taking a look with me

thheller16:06:50

I mean you can go totally crazy with hacks but that seems kinda scary

thheller16:06:05

(defn ^:export my-fn [x] ...) and as .filter you use (js/Function. "function filterMe(x) { return _fn(x); }") 😛

thheller16:06:06

or was it (js/Function. "x" "return _fn(x);"), can't remember precisely

thheller16:06:27

kinda absurd to construct a function that way, but that would stay equal 😉

knubie16:06:23

I’ll play around with it, but thank you for suggestions!

Michaël Salihi19:06:02

Me again :) I just finished the Reagent front end integration of this demo app https://inertia.prestance-design.com/js and I'm going to tackle the optimization. For that I use the useful Shadow-cljs report and it seems to me that overall it looks to be well optimized? https://inertia.prestance-design.com/js/report.html Someone in the know could give me an opinion? Is there something to do in particular at the level of the CLJS bundle?

Michaël Salihi20:06:01

Or the final size seems reasonable.

thheller20:06:06

looks reasonable. below 150kb gzip is good

Michaël Salihi20:06:57

Perfect, thanks for taking the time 👍