shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Alexis Vincent 2020-12-30T13:29:19.205700Z

@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

thheller 2020-12-30T14:05:50.206300Z

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

thheller 2020-12-30T14:06:03.206600Z

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

thheller 2020-12-30T14:06:54.207Z

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

thheller 2020-12-30T14:07:18.207300Z

I mean the client never downloads server side code?

Alexis Vincent 2020-12-30T14:12:52.209400Z

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 Vincent 2020-12-30T14:13:47.210300Z

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

thheller 2020-12-30T16:42:10.211600Z

@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.

thheller 2020-12-30T16:42:48.212200Z

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 Vincent 2020-12-30T17:10:51.213500Z

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

thheller 2020-12-30T17:34:33.214500Z

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

thheller 2020-12-30T17:34:44.214900Z

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

thheller 2020-12-30T17:35:19.215700Z

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 Vincent 2020-12-30T17:47:09.217700Z

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 Vincent 2020-12-30T17:47:36.218200Z

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

thheller 2020-12-30T19:13:50.218900Z

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

thheller 2020-12-30T19:14:05.219300Z

shouldn't change much on the configuration side though