clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
johanatan 2020-09-24T02:34:21.022100Z

Honestly I think i will just emit a dynamic def with a macro. Thx!

johanatan 2020-09-24T03:34:57.022300Z

Also, looks like my hunch was correct: https://gist.github.com/eyelidlessness/e760c5350b113a0bbcab

neilyio 2020-09-24T15:03:05.003100Z

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?

unbalanced 2020-09-24T17:36:46.003600Z

you mean on advanced compilation?

neilyio 2020-09-24T17:49:56.006300Z

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.

unbalanced 2020-09-24T20:38:33.006800Z

😬 ah that could be tough

neilyio 2020-09-24T20:38:52.007400Z

Tell me about it I can't find an answer anywhere haha

unbalanced 2020-09-24T20:38:57.007600Z

it's the "each js" file that would be the tougher part, I think

unbalanced 2020-09-24T20:39:24.008400Z

Because you'd have to do something like code-splitting to get that to work in a single project

neilyio 2020-09-24T20:40:03.009200Z

Yep. I was hoping there'd be a compiler option to just "mirror" my source directory of .cljs files with the output .js files.

neilyio 2020-09-24T20:42:02.009900Z

@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

unbalanced 2020-09-24T20:43:56.010400Z

mmm that would be a very good approach. Probably easier than what I was going to suggest

neilyio 2020-09-24T20:44:22.011Z

Would still love to hear your idea. I'm always happy to complicate these things.

unbalanced 2020-09-24T20:45:12.011300Z

Oh man, you're talking to the right cat avatar internet guy, then

unbalanced 2020-09-24T20:52:39.012400Z

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

unbalanced 2020-09-24T20:53:19.012800Z

Then in the files themselves you could do something like (js* "module.exports = blah") at the bottom

unbalanced 2020-09-24T20:53:40.013Z

I'm not saying it's better. But it IS complicated!

unbalanced 2020-09-24T20:55:28.013200Z

Another option is... you could use a combination of :closure-defines with a case statement at the bottom of the page

unbalanced 2020-09-24T20:56:56.013400Z

(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 instance

unbalanced 2020-09-24T20:57:13.013600Z

hmm maybe not complicated enough

unbalanced 2020-09-24T20:57:22.013800Z

I'll keep thinking about it :rolling_on_the_floor_laughing:

neilyio 2020-09-24T20:59:44.014100Z

That's a wild approach. I'll have to try it out, thanks for walking me through it!

thheller 2020-09-24T21:27:24.014300Z

@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

💯 1
1
thheller 2020-09-24T21:28:06.014500Z

you can of course do it but something to be aware of

unbalanced 2020-09-24T22:09:05.015900Z

Absolutely... my only claim was that it was minimally viable and overly complex 🤪

unbalanced 2020-09-24T22:09:48.016600Z

I love the module idea!

John Christopher Jones 2020-09-24T22:26:22.022Z

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

John Christopher Jones 2020-09-24T22:30:23.022800Z

Also there's https://shadow-cljs.github.io/docs/UsersGuide.html#_boot, so you can keep using Boot