Fork me on GitHub
#shadow-cljs
<
2021-12-09
>
metasoarous19:12:53

Hi folks. Is it possible to use shadow-cljs as a library, to (e.g.) compile a cljs string into a js string? Thanks.

thheller20:12:35

technically yes but no. depending on what you are doing you are likely better off using cljs.analyzer directly

metasoarous21:12:23

Wonderful! Thank you! Looks like cljs.build.api/build does most of what I want, as long as I don't want advanced optimizations. Would there be a way to have pieces of shadow assist with that?

thheller21:12:03

without knowing what you intend to do I can't answer that

metasoarous21:12:15

This is for #oz I want to allow users of oz to build snippets of cljs->javascript in with their notebooks/blog-posts/documentation.

thheller21:12:10

define "snippets"?

metasoarous22:12:02

There are two goals with respect to this: • Make it possible to inline reagent components in the context of a document (code block in a markdown file, for example) • Plug reagent components into a multimethod dispatch system, so that oz's live-view can be "extended"

thheller22:12:34

that would require building the live-view code as part of the snippets?

metasoarous22:12:58

Yes, I believe so

thheller22:12:59

(I'm assuming here you ship a pre-built .js file currently?)

thheller22:12:03

extending a :advanced build after the fact is pretty much impossible

metasoarous22:12:23

Got it; That's sort of what I was afraid of.

thheller22:12:51

well you can always just stick to basic JS types, that won't be a problem

thheller22:12:09

but multi methods and general CLJS datatypes won't really work

metasoarous22:12:51

OK; That makes sense.

thheller22:12:21

my general recommendation would be a take your snippets and somehow generate a regular .cljs file out of that

thheller22:12:49

then compile that as a regular build via the CLJ API (same as a regular build config really)

thheller22:12:16

that will ensure that you get a file you can actually load on your html page

thheller22:12:52

just compiling snippets leaves a lot of manual stuff for you to do that are easy to mess up (eg. loading all sources in proper dependency order)

thheller22:12:33

but yeah you probably need to compile some or all of your other live-view related code together with that

metasoarous22:12:21

That makes sense. Thank you!