Letโs say I have a bunch of pure clojure functions Can I use Clojurescript compiler to turn them into a big js file without any dependencies and include it into node, browser, react native, etc?
I think so, like using shadow-cljs, you can build it for different targets, browser, esm, node, etc.
of course you can. that is what clojurescript basically is ๐
however many people often misjudge the ergonomics. "no dependencies" still means that you'll be including cljs.core for all the base functions/datastructures you are going to use. so the baseline is about 30kb gzip and it can often involve a lot of datastructure conversion overhead when working with JS directly, just because JS doesn't understand clojure datastructures and you'll rarely work with JS objects directly in CLJS. you of course can but it won't exactly look like idiomatic CLJS code
Thank you, the thing I don't get is this: when I compile with target browser or bundle clj -M -m cljs.main --target browser --output-to main.js -c hello.core I got something like this
window.CLOSURE_UNCOMPILED_DEFINES = {"cljs.core._STAR_target_STAR_":"browser"};
window.CLOSURE_NO_DEPS = true;
....
So, window reference, which is not universal
When I use target node I got
require(path.join(path.resolve(".")
which is ofc node specific
What I want is just a big js file without document or require etc, which I can include to JSC, react-native, node, or browser
Probably I'm missing something idkcljs.main --target browser. this command literally tells it to expect a browser environment and generate code accordingly
shadow-cljs has support for more generic targets
blame JS for having so many different "delivery methods"
right, browser is obvious, but I thought maybe none is what I need but seems like no, so I thought maybe thereโs something else, probably config toggle or something, especially using bundle
cljs.main doesn't have many options regarding this. shadow-cljs does.
Iโll try shadow thank you! Seems like generic is something useful to include in cljs, I was thinking about writing core in Clojurescript, but still use js for react expo, cause hooks and modern react spoiled all ecosystem..
well even JS has rules for how you access stuff. the "just throw it into the global scope" ways of old aren't really used anymore. so instead you'd use something like ESM (or commonjs before that)
Yea, universal ESM module sounds even better for what I thought of Probably webpack could do the trick
https://shadow-cljs.github.io/docs/UsersGuide.html#target-esm
I wonder if anyone still uses stock cljs at this point.. ๐ถโ๐ซ๏ธ
shadow-cljs is just a build tool. it is still just CLJS ๐ the regular cljs.main is not used a lot according to the clojure survey results