Fork me on GitHub
#clojurescript
<
2023-02-12
>
john2x21:02:08

I'm trying to understand code splitting with shadow-cljs https://shadow-cljs.github.io/docs/UsersGuide.html#CodeSplitting. I want to keep my app multi-paged to keep things familiar for me, but I have some pages where I need some interactivity. I think how code splitting is described is what I want. But I'm not sure I understand what is meant by the :shared module. Does it mean if home, login, and protected require something from common (via ns)? Or would require s get compiled into each module and shared is something else?

john2x21:02:45

I guess what I'm asking is, do I need to copy-paste the :required namespaces in my cljs files in the :shared module definition?

john2x22:02:45

I think I got it working. So I left :shared empty as mentioned in the 'tip'. And I added both the shared.js and login.js scripts in the html page.

john2x06:02:48

Thank you. I haven't seen that.

john2x06:02:57

ah that's specifically talking about splitting/lazy-loading React components. How should I approach splitting without Reagent/React? e.g. I want to compile self-contained scripts that are only needed in specific pages. Would I need separate :builds entries for each script? Does that end up with each build having some duplication of the Clojurescript runtime?

thheller06:02:12

no, the exact same stuff applies. you seem to have figured out the correct approach

thheller06:02:27

shared is everything that multiple pages may use

thheller06:02:32

login is only what login uses

thheller06:02:13

you can just load them directly via html script tags, no need to load them dynamically driven by react components

thheller06:02:39

so if you only need that then you seem to be done

thheller06:02:08

with :target :esm it would even be fine to just include the login.js file and let it load the rest itself

john2x06:02:34

ah sweet. Thanks Thomas! That clarifies things.

thheller06:02:47

if you want a more "modern" appraoch that is. but :target :browser is still totally fine and a lot more flexible in many ways

👍 2