Fork me on GitHub
#shadow-cljs
<
2022-08-06
>
Schpaa07:08:58

How can I trigger compilation by changing a file that is not a sourcefile? (it’s a css file I include for lambdaislands ornament, which is included in the :flush stage triggered by a hook in shadow-cljs.edn)

thheller08:08:49

not supported as I strongly recommend not doing anything like this in build hooks

thheller08:08:50

how is that css file relevant to the build?

Schpaa08:08:21

That css contains color-variables that are included in the file that is built with ornament

thheller08:08:05

well yeah, thats a prime example of why I strongly discourage using build hooks for this

thheller08:08:18

you constrain yourself to only being able to generate CSS by running a shadow-cljs build

Schpaa08:08:32

thats kind of the point

Schpaa08:08:22

ornament picks up styles I’ve defined in cljs and builds the css

Schpaa08:08:53

It’s fantastic to work with

thheller08:08:20

in a build hook this would be (assoc-in build-state [:compiler-env :cljs.analyzer/namespaces your.ns :shadow.resource/resource-refs "some/path.css"] last-mod)

thheller08:08:44

but it needs to be on the classpath for this to work

thheller08:08:10

so I guess "resources/public/styles.css" becomes "public/styles.css"

Schpaa08:08:15

ok, I’ll do some research, thanks for the pointers

thheller08:08:38

(need to do this before compilation though, flush is too later)

thheller08:08:01

or I guess in the :compiler-finish stage would do it

👍 1
thheller08:08:22

hmm yeah this is not the best idea

thheller08:08:36

I think the best option is to handle it outside

Schpaa08:08:47

I think I solved it (for my use-case) by adding the file to the classpath and using a simple (inline …) in one of the sources

thheller08:08:50

just touch a-source-file.cljs to trigger a recompilation after editing the css

thheller08:08:15

sure that works too

Schpaa08:08:26

The thing is, this is just for my convenience, saving the css triggers the recompilation and I dont have to go back and forth saving a cljs file to rebuild the css. Now it works just as I wanted, super!

thheller08:08:38

hmm yeah I guess this needs to stay a build hook since it looks at a runtime atom

👍 1