Fork me on GitHub
#shadow-cljs
<
2022-08-12
>
jon rostran22:08:38

is it possible to import cljs in a clj build hook file ?

thheller22:08:34

sorry I don't understand the question

thheller22:08:43

what do you mean by "import cljs"

jon rostran22:08:21

a build hook file importing a function in the cljs source-paths and invoking it

thheller22:08:47

what does that mean?

thheller22:08:07

CLJ only runs the JVM code, it cannot invoke CLJS/JS code no

jon rostran22:08:54

I have a function written in a cljs file with the cljs file ext. the hook file is written in cljc ext and I need to grab a function in the cljs file to use in the cljc hook file

thheller22:08:30

don't know why your hook is cljc but it sound like you are trying to do something that is not possible?

thheller22:08:39

maybe try to describe what you are trying to do more?

thheller22:08:10

what does this function do?

jon rostran22:08:15

I have a hooks.main file

jon rostran22:08:39

and it calls hiccup html, I need to grab a component in the cljs side and call it inside hiccups html

thheller22:08:00

what do you mean by "call it inside". this is CLJS code, so it is meant to run in the browser?

thheller22:08:19

if you are trying to use hooks to do some kind of server side rendering stop, they are not meant to do that and can't do that

jon rostran22:08:26

I need to call the function that wraps the component inside hiccup’s html form

jon rostran22:08:37

so that it returns a string for example

jon rostran22:08:08

it’s means to compile to an index.html file

jon rostran22:08:15

it’s meant*

jon rostran22:08:30

but I need to insert a component when the index.html builds

jon rostran22:08:40

since I already have it written somewhere else

thheller22:08:00

what do you mean by "insert a component"?

thheller22:08:19

I mean a component is a dynamic thing that runs in the browser (I assume)

thheller22:08:48

but again .. this sounds like you are trying to do server-side rendering

thheller22:08:57

which hooks shouldn't do and really cannot do properly

thheller22:08:22

or I just fundamentally do not understand what you are asking 😛

jon rostran22:08:27

I mean that when the hook runs and invokes hiccups html, I want to write a symbol that references a reagent component definition written in cljs, then I want that fn call to return inside the html hiccup form, I want to eval it and return when the build calls html

jon rostran22:08:24

said component is just hiccup markup doesn’t have anything fancy

thheller22:08:27

so you want to take the html this component generates and dump it statically into a .html file

thheller22:08:49

this is generally called server-side rendering. this is not supported and build hooks cannot do that and really absolutely should not do that

jon rostran23:08:19

the build hook outputs a static index.html file, in that file I want to include that component written in cljs/reagent

thheller23:08:34

yes, you keep saying that but it doesn't make sense 😛

jon rostran23:08:59

I think what u said earlier is what I’m trying to do

jon rostran23:08:29

anyway, is this possible? tried requiring the cljs with reader conditional

jon rostran23:08:37

but doesn’t work

thheller23:08:13

no, fundamentally not possible with reader conditionals

thheller23:08:22

and also not possible in build hooks

thheller23:08:18

I mean everything is possible but this is not what build hooks are designed to do

thheller23:08:35

so you are better off doing is elsewhere

jon rostran23:08:57

ok, I guess my build hook will be used strictly to prepare a static index.html to then mount the app

thheller23:08:47

I mean you can make a :node-script build that takes your CLJS code and uses react-based server side rendering to create that index.html

thheller23:08:51

that is totally doable

thheller23:08:39

but combining this with build hooks doesn't make sense and shouldn't be done