Honestly I think i will just emit a dynamic def
with a macro. Thx!
Also, looks like my hunch was correct: https://gist.github.com/eyelidlessness/e760c5350b113a0bbcab
I need my generated Javascript to have a module.exports = my_cljs_func
, I'm not really sure where to start with this. I'm using Boot right now, but it seems like this is either somehow done with ^:export
metadata or https://clojurescript.org/reference/compiler-options#target-fn. Any thoughts?
you mean on advanced compilation?
I'd like to know if it's possible on none, simple, or advanced. I'm trying to use ClojureScript with Next.js for static site generation, and Next.js requires one .js
file for each generated html
web page. Each .js
file needs to export its render function with module.exports = my_render_func
.
😬 ah that could be tough
Tell me about it I can't find an answer anywhere haha
it's the "each js" file that would be the tougher part, I think
Because you'd have to do something like code-splitting to get that to work in a single project
Yep. I was hoping there'd be a compiler option to just "mirror" my source directory of .cljs
files with the output .js
files.
@thheller had a clever idea that will save me in the meantime: you could just create a `foo.js` yourself that just has `module.exports = require("./path-to-npm-module-output/your.ns").the_export;` with `(defn ^:export the-export [foo bar] ...)` in that ns
mmm that would be a very good approach. Probably easier than what I was going to suggest
Would still love to hear your idea. I'm always happy to complicate these things.
Oh man, you're talking to the right cat avatar internet guy, then
So this is a figwheel concept (apologies, @thheller , I haven't learned the hotness yet). https://github.com/jjtolton/rocinante/blob/master/src/clj/new/rocinante/dev.cljs.edn and https://github.com/jjtolton/rocinante/blob/master/src/clj/new/rocinante/dev.cljs.edn I have two different build profiles (worker and regular). They correspond with https://github.com/jjtolton/rocinante/blob/master/src/clj/new/rocinante/src/cljs/base/core.cljs and https://github.com/jjtolton/rocinante/blob/master/src/clj/new/rocinante/src/cljs/base/worker.cljs I build them https://github.com/jjtolton/rocinante/blob/master/src/clj/new/rocinante/Makefile#L17
It's an easy way to build two different files. I imagine it would be fairly easy to produce multiple js files this way in advanced compilation. Note that I would ABSOLUTELY use the prefix option to prevent namespace collisions
Then in the files themselves you could do something like
(js* "module.exports = blah")
at the bottom
I'm not saying it's better. But it IS complicated!
Another option is... you could use a combination of :closure-defines
with a case statement at the bottom of the page
(case goog/PAGE
"main" (js* "module.exports = main_render)
"blah" (js* "module.exports = blah_render))
where goog/PAGE
is defined with
:closure-defines {PAGE "main"}
for instancehmm maybe not complicated enough
I'll keep thinking about it :rolling_on_the_floor_laughing:
That's a wild approach. I'll have to try it out, thanks for walking me through it!
@goomba your approach to workers is not ideal. both builds will duplicate a lot of code and none of it is shared. if you use :modules
to split the code you can share code which means the user only has to download a large portion once and the page/worker can share it
you can of course do it but something to be aware of
Absolutely... my only claim was that it was minimally viable and overly complex 🤪
I love the module idea!
@neil.hansen.31 Sounds like a good idea to start with. I did find that this is https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-library. You could probably automate rewriting a build target section of your shadow-cljs.edn
based on the contents of your pages
namespace. 🙂
Also there's https://shadow-cljs.github.io/docs/UsersGuide.html#_boot, so you can keep using Boot