Fork me on GitHub
Vincent Cantin09:01:05

Using Shadow-cljs, is there a way to run a hook inside the context of the reloaded cljc source files? From my test on the hooks, it seems that the source code is only loaded once.


scanning for generic things like that is difficult but build hooks receive the entire build state and can inspect it however they need

Vincent Cantin10:01:44

I took a look at the build-state and made the mistake of printing its content 😛


the best option I have found so far however is using a dedicated css macro or so that collects these things during compilation. much easier to extract but slightly more verbose in the code

(def button-style (css :border :p-2 :shadow :lg/p-4))
or so


(tap> build-state) and look at it in the inspect UI

Vincent Cantin10:01:31

oh, good idea (for the tap>)


:sources has all the sources


:output has all the outputs of those sources (in :flush) stage, otherwise might still be empty

Vincent Cantin10:01:50

I made a macro which adds the css in the metadata attached to the clojure var already. I am looking at how to read it from the hook.


it stores state in the analyzer data for the namespace


you could read that out later in the build hook via [:compiler-env :cljs.analyzer/namespaces your.ns :your.thing/key] or so

Vincent Cantin10:01:21

Thx, I am taking a look now.

Vincent Cantin12:01:25

@U05224H0W this worked !

(tap> (get-in build-state
Big thank you !


when you add custom keys to the analyzer data make sure they are namespaced


otherwise you might at some point clash with implementation details

👌 3