This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-24
Channels
- # announcements (6)
- # architecture (9)
- # aws (2)
- # babashka (49)
- # beginners (160)
- # boot (19)
- # calva (9)
- # cider (16)
- # clj-kondo (17)
- # cljfx (9)
- # clojure (143)
- # clojure-australia (5)
- # clojure-berlin (1)
- # clojure-czech (3)
- # clojure-europe (64)
- # clojure-france (1)
- # clojure-italy (12)
- # clojure-nl (4)
- # clojure-spec (6)
- # clojure-uk (47)
- # clojurescript (27)
- # code-reviews (5)
- # conjure (45)
- # cursive (47)
- # datascript (2)
- # datomic (21)
- # events (1)
- # fulcro (9)
- # graalvm (4)
- # graphql (2)
- # jackdaw (22)
- # jobs (3)
- # kaocha (6)
- # london-clojurians (1)
- # luminus (4)
- # malli (19)
- # meander (136)
- # pathom (4)
- # pedestal (2)
- # re-frame (15)
- # reitit (2)
- # remote-jobs (2)
- # rum (12)
- # sci (1)
- # shadow-cljs (100)
- # spacemacs (10)
- # sql (1)
- # tools-deps (30)
- # vrac (1)
- # xtdb (30)
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
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
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:
@U3BALC2HH 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
Absolutely... my only claim was that it was minimally viable and overly complex 🤪
I love the module idea!
Oh man, you're talking to the right cat avatar internet guy, then
@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