shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2021-06-10T05:37:56.450700Z

How do I update new dependencies in shadow-cljs?

2021-06-10T05:42:53.450800Z

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.

2021-06-10T05:43:06.451Z

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

Aron 2021-06-10T05:43:11.451200Z

I just restart shadow-cljs

2021-06-10T05:44:25.451400Z

shouldn’t

shadow-cljs watch app 
do?

thheller 2021-06-10T06:20:36.451700Z

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

thheller 2021-06-10T06:29:58.451900Z

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.

2021-06-10T06:36:12.452100Z

Thanks! I ran

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

thheller 2021-06-10T06:38:54.452300Z

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

1👍1🙏
2021-06-10T09:18:51.453300Z

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?

thheller 2021-06-10T10:34:54.453800Z

@admin055 if you just have a static html file you can use this hook https://github.com/thheller/shadow-cljs/blob/master/shadow-cljs.edn#L147-L149

thheller 2021-06-10T10:35:42.454400Z

that'll take the source and rewrite the html script tags eg. https://github.com/thheller/shadow-cljs/blob/master/out/demo-browser/index.src.html#L10-L11

thheller 2021-06-10T10:36:02.454800Z

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

thheller 2021-06-10T10:36:13.455200Z

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

thheller 2021-06-10T10:37:40.455900Z

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

2021-06-10T10:42:53.456200Z

> 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.

2021-06-10T10:44:15.456600Z

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

2021-06-10T10:50:03.457100Z

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

1👆1😎
2021-06-10T13:39:34.459300Z

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?

2021-06-10T13:39:58.459700Z

The path must be in the classpath too?

2021-06-10T13:40:23.460200Z

I tried multiple solution but no success.

thheller 2021-06-10T13:40:24.460300Z

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

2021-06-10T13:41:28.460600Z

Yes, this is the case.

2021-06-10T13:41:51.461200Z

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

thheller 2021-06-10T13:41:56.461400Z

you need to restart the watch for this to take effect

2021-06-10T13:42:40.462400Z

Oh ok, I try to restart

2021-06-10T13:45:20.463Z

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

thheller 2021-06-10T13:45:44.463400Z

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

2021-06-10T13:47:34.464300Z

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

2021-06-10T13:48:01.464800Z

CSS reload

thheller 2021-06-10T13:48:03.464900Z

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

thheller 2021-06-10T13:48:30.465300Z

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

2021-06-10T13:48:47.465600Z

Yes the output file.

2021-06-10T13:48:51.465800Z

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

thheller 2021-06-10T13:49:46.466800Z

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

2021-06-10T13:50:15.467300Z

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?

thheller 2021-06-10T13:50:25.467500Z

no, doesn't care

2021-06-10T13:50:58.467900Z

OK, good to know

2021-06-10T13:52:20.469400Z

> 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

thheller 2021-06-10T13:52:38.469700Z

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

thheller 2021-06-10T13:53:19.470500Z

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

thheller 2021-06-10T13:53:32.470900Z

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

2021-06-10T13:55:37.471700Z

Load CSS shows up and CSS reload now, perfect!

2021-06-10T13:57:36.472100Z

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

2021-06-10T14:00:04.473200Z

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

1❤️
knubie 2021-06-10T15:15:45.475500Z

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).

thheller 2021-06-10T15:18:09.476300Z

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

thheller 2021-06-10T15:19:14.476700Z

you mean you are calling toString on a function?

knubie 2021-06-10T16:23:15.476900Z

@thheller yes sorry

knubie 2021-06-10T16:23:28.477300Z

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

knubie 2021-06-10T16:24:10.477800Z

so it looks like myFn.toString()

knubie 2021-06-10T16:24:41.478300Z

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

knubie 2021-06-10T16:24:52.478600Z

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

knubie 2021-06-10T16:25:22.479200Z

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

thheller 2021-06-10T16:26:07.479600Z

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

thheller 2021-06-10T16:27:16.480500Z

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

thheller 2021-06-10T16:28:04.481200Z

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

knubie 2021-06-10T16:31:02.481500Z

Sure, the documentation on the replication protocol is here: https://docs.couchdb.org/en/3.1.1/replication/protocol.html#generate-replication-id

knubie 2021-06-10T16:31:50.482300Z

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

knubie 2021-06-10T16:34:16.483Z

what if I import the function from a javascript module?

thheller 2021-06-10T16:35:24.483800Z

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

knubie 2021-06-10T16:37:32.484700Z

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

thheller 2021-06-10T16:38:41.485400Z

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

thheller 2021-06-10T16:39:44.486100Z

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

knubie 2021-06-10T16:40:34.486400Z

Yeah seems like that would be the case

knubie 2021-06-10T16:40:46.486700Z

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

knubie 2021-06-10T16:40:50.486900Z

thanks for taking a look with me

thheller 2021-06-10T16:41:50.487500Z

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

thheller 2021-06-10T16:43:05.488900Z

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

thheller 2021-06-10T16:44:06.489500Z

or was it (js/Function. "x" "return <http://your.full.ns.my|your.full.ns.my>_fn(x);"), can't remember precisely

thheller 2021-06-10T16:44:27.489900Z

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

knubie 2021-06-10T16:44:57.490100Z

hmm

knubie 2021-06-10T16:45:23.490600Z

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

2021-06-10T19:58:02.492Z

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?

2021-06-10T20:08:01.492400Z

Or the final size seems reasonable.

thheller 2021-06-10T20:32:06.492800Z

looks reasonable. below 150kb gzip is good

2021-06-10T20:32:57.493200Z

Perfect, thanks for taking the time 👍