How do you automatically create multiple modules based on the files in a folder

Not sure if this use case is supported, or even if it’s a sane one. Basically, I want JS specific to each page. I will have .cljc file for each page. I basically want this file compiled into its own module. So for example, given the files “pages/login.cljc” and “pages/contact.cljc”, I would like to generate a “login.js” and “contact.js”. Right now I’m doing that with this shadow-cljs.edn modules config:

:app {:entries []}
:login {:entries [project.pages.login]
        :depends-on #{:app}}
:contact {:entire []
          :depends-on #{:app}}

But I already have a list of pages elsewhere in the code for things like routes. I would love to use that list of pages to generate these modules, or even just infer it from the files in the pages directory. Is this possible?

Not supported and usually not desireable.

I sort of explained this in my blog post about code splitting. Generally splitting by page will lead to non-optimal results in almost all cases. Ending up with with large app.js module and possibly tiny (<1KB) .js file for each page. Also the :depends-on here is crucial since it will be very common where certain pages share certain code but others do that. With only one shared module it only has one place to go.

Tweaking the :modules is something you should be doing when the code is written based on the build reports.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.