Closed
Description
Great project! Thank you
Would you please provide a UMD build for the compiler published to npm?
I want to use the compiler in a web worker. Currently firefox does not support worker module.
I see you already have esbuild as a dependency.
This should be something like:
esbuild index.js --bundle --minify --format=iife --global-name=CherryCljs --outfile=lib/cherry.umd.js
thank you
Activity
borkdude commentedon Jun 3, 2023
@hatemhosny Before I pursue this solution, can you maybe try this locally, or provide an example of how I could test this in a web worker? Note that the standard library of cherry is also compiled as an ES6 module, isn't this a problem?
hatemhosny commentedon Jun 3, 2023
@borkdude
thank you for the response.
This is an example for the proposed build:
repo: https://github.com/live-codes/cherry-cljs-compiler
build cmd: https://github.com/live-codes/cherry-cljs-compiler/blob/main/package.json#L8
output: https://github.com/live-codes/cherry-cljs-compiler/blob/main/cherry.umd.js
which was published to npm to be hosted on: https://cdn.jsdelivr.net/npm/@live-codes/cherry-cljs-compiler@0.0.3/cherry.umd.js
and this is a basic usage example for module and classic workers:
https://hatemhosny.github.io/cherry-cljs/
please note that the module worker does not work by default in Firefox (only works after enabling a flag or in developer edition)
source code: https://github.com/hatemhosny/cherry-cljs
I have no problem running the compiled code as a module. I just need the compiler to run in the web worker for performance reasons.
Note: I'm doing that to add ClojureScript support to https://livecodes.io/ (https://github.com/live-codes/livecodes) - documentations
your project is great and does exactly what I need
Thank you very much
borkdude commentedon Jun 3, 2023
Would
index.umd.js
make more sense maybe, since we also haveindex.js
? Should I change anything inpackage.json
?Why not
.cjs
instead of.js
?hatemhosny commentedon Jun 3, 2023
May be. But I think of
index.js
as the default file. While the UMD will need to be specified by full URL:https://cdn.jsdelivr.net/npm/cherry-cljs@0.0.3/index.umd.js
vshttps://cdn.jsdelivr.net/npm/cherry-cljs@0.0.3/cherry.umd.js
That's just a stylistic opinion.
you may want to add these fields to
package.json
(more details)also these would allow you to import from
https://cdn.jsdelivr.net/npm/cherry-cljs@0.0.3
rather thanhttps://cdn.jsdelivr.net/npm/cherry-cljs@0.0.3/index.js
I do not think there is a field where we specify UMD builds. They are usually loaded by the browser, which requires us to specify full path anyways.
That would be a third build format for commonjs.
For UMD builds, use
iife
Also, since the API is very simple, it would be easy to add TypeScript support by adding this simple file:
index.d.ts
and referring to it in
types
field inpackage.json
(see above)hatemhosny commentedon Jun 4, 2023
@borkdude
I have added provisional support for ClojureScript in LiveCodes using your great library.
ClojureScript starter template (on the development build): https://dev.livecodes.io/?template=clojurescript
I have given credit to your project in the documentations: https://dev.livecodes.io/docs/languages/clojurescript
I'm currently temporarily using the UMD build I have published, till the official build is ready.
Thank you very much 🙏
borkdude commentedon Jun 4, 2023
@hatemhosny Very cool! I'll just follow your suggestion and will make the .umd.js available shortly.
I think it'll be better to mention CLJS as "CLJS (cherry)" since this isn't the official CLJS compiler, so mentioning cherry (with a link to this project) will probably be best.
borkdude commentedon Jun 4, 2023
It's published now. Please let me know the final link to livecodes.io, then I'll share it around :)
hatemhosny commentedon Jun 4, 2023
@borkdude
I followed your suggestion adding (cherry) to the title of CLJS (https://dev.livecodes.io/?template=clojurescript)
the language info screen does indeed link to your project
Thank you for providing the umd build. I have updated LiveCodes to use your file, and archived my temporary repo with a deprecation notice.
These updates should be published with the next release of LiveCodes (hopefully soon).
Thanks a lot for offering to share it. Very grateful indeed. I will let you know when it is ready.
hatemhosny commentedon Aug 6, 2023
Hi @borkdude
LiveCodes is now publicly released. Please read the announcement post.
This is the link to cljs starter template: https://livecodes.io/?template=clojurescript
A quick link to start an empty project in cljs: https://livecodes.io/?cljs
Documentations for ClojureScript language support in LiveCodes (including React/JSX usage): https://livecodes.io/docs/languages/clojurescript/
Thank you for making that possible :)
borkdude commentedon Aug 6, 2023
Awesome, I shared this news on Twitter, Mastodon and Bluesky :)
hatemhosny commentedon Aug 6, 2023
Thank you, @borkdude ❤️
You may find this useful. This code can be used to embed a ClojureScript playground in any webpage:
Preview
for details and more options, check the SDK documentations.