Fork me on GitHub
#shadow-cljs
<
2020-12-30
>
Alexis Vincent13:12:19

@thheller If I’m compiling :node-library is there any way to do dynamic module loading? I’m working on a hybrid client / server ssr tool for cljs akin to next js. I have library code that I want to require client modules and for this to work on both the client and the server. The main issue I can forsee is if I try to have multiple entry points on the server. Any comments? For more context: • The tool is called clam. • I have a node cli with a clam dev command that spawns a clj process, which then starts a shadow server and call watch* with 2 generated build configs. • I generate 2 builds, a client and a server. :target :browser and target :node-library , currently these both import client react trees, with the server one adding http handlers and ssr. • I want to augment this to support dynamic module loading on the client and control the loading experience. The issue I can see is that since its no longer a single require tree, I dont know how that will play with node-library

thheller14:12:50

:node-library cannot do this and isn't meant to no.

thheller14:12:03

you can try :target :esm maybe that fits your needs

thheller14:12:54

but I don't quite see how server side stuff relates to client side stuff in any way?

thheller14:12:18

I mean the client never downloads server side code?

Alexis Vincent14:12:52

Thanks Thomas. Does :esm support repl and hot reloading? It’s more loading and executing client code on the server, but if the client code has dynamic module loading then It seems this is no longer possible

Alexis Vincent14:12:47

I don’t mind doing some custom build stuff to get this working, since I completely control the build step

thheller16:12:10

@mail024 it entirely depends on how you do the dynamic module loading stuff. its code in your control so you can just write one implementation for the browser and one for node.

thheller16:12:48

esm does support REPL and hot-reload yes but you really should use two separate builds and not try to make one build do two things

Alexis Vincent17:12:51

I definitely have 2 builds. I guess what I’m asking is if its possible to do dynamic module loading, inline require in node using cljs

thheller17:12:33

that entirely depends on how YOU do dynamic module loading in the first place

thheller17:12:44

as far as shadow-cljs is concerned it is putting .js files on disk

thheller17:12:19

how you load them is your concern. one option is to use shadow.loader which only works in :browser builds. you do not have to use that though. you can completely roll your own that works in both browser and node

Alexis Vincent17:12:09

right! thanks for the clarification, I guess I assumed the .js files outputted assumed a browser environment. Or that the files outputted with other builds don’t work without entries, etc.

Alexis Vincent17:12:36

Whats the status on esm builds? Theres no mention in the docs

thheller19:12:50

waiting on some stuff in the closure compiler before further work on this

thheller19:12:05

shouldn't change much on the configuration side though