Fork me on GitHub
#shadow-cljs
<
2019-09-03
>
kasuko12:09:57

Does anyone have advice on writing multiple shadow-cljs libraries for use in Javascript? Our application was at one time fully CLJS and in one project. Now due to business reasons the company is writing more pure Javascript libraries. We are using shadow-cljs to utilize our previous code in a JS ecosystem. However, I personally do not want to get rid of CLJS, so if I can use shadow-cljs to write libraries that can be used in Javascript (which it appears I can) I'd be ecstatic. However, before I go and write a bunch of libraries with Shadow CLJS I was wondering if I should take into account things like Clojure's Core being included multiple times, etc?

thheller12:09:17

@kasuko writing mulitple libraries in CLJS and including them in a regular JS builds is not a good idea

thheller12:09:38

including cljs.core multiple times is really bad as you mentioned

thheller12:09:49

but also the libraries will not be compatible with each other

thheller13:09:23

what you can do is create a :npm-module build that outputs all CLJS you want to use in the JS build

kasuko15:09:24

Is it possible to do some kind of code-splitting with that? For example if I build an authentication library I want to be able to provide that without including every libary

thheller16:09:13

not sure what you mean

thheller16:09:25

code splitting would be done by webpack or whatever you use on the JS side

thheller16:09:44

but CLJS in general is not great for writing JS libraries. :advanced optimizations really aren't suited for that

thheller16:09:59

and the code is too big with :simple

David Pham16:09:04

Can shadow-cljs replace Lumo for writing shell scripts? Since you can call node your_output_cljs.js?

thheller16:09:51

@neo2551 depends. :node-script is meant to build scripts which you can run later yes

thheller16:09:23

but the edit -> compile -> run delay makes it impractical if you just want some ad-hoc scripting

thheller16:09:54

but once the output is built it'll be faster than lumo since it doesn't have to load the compiler first

David Pham16:09:21

Hum... I usually shadow-cljs watch app when I am writing my script :)

David Pham16:09:36

(I just avoid to call the side effects part haha)

thheller16:09:40

yeah thats fine. but you still have to run shadow-cljs first (which takes some time to start)

David Pham16:09:17

But once it is built, the output would have be optimal with node?

thheller16:09:35

yes (and it doesn't rely on shadow-cljs anymore, unlike lumo)

David Pham16:09:19

Yep, perfect! (You should totally sell this as cool feature) :)

sogaiu00:09:01

as a recent user of this feature i'm curious whether the resulting js would be dependent on the installed node version.

thheller09:09:59

yes, it is just a javascript file.

sogaiu10:09:09

thanks -- so it seems like recompilation might be necessary when using with different node environments

thheller10:09:23

no it doesn't?

sogaiu11:09:28

ah, right, as you said the product is just a js file so if node's behavior changes, that potentially affects all js files regardless of where they originate. thanks for the deconfusion.

David Pham16:09:41

Hell, i don’t understand shell scripts

sjharms16:09:34

As a very new person to Shadow-cljs, I was wondering where I could find a tutorial or guide on setting up a project with deps.edn, clojure cli, shadow-cljs and re-frame. Is there one that exists?

sjharms16:09:59

Story so far: 1. Install NPM 2. Install shadow-cljs 3. Install clojure cli 4. Copy deps.edn from https://github.com/Day8/re-frame/blob/master/deps.edn 5. shadow-cljs init 6. npm init

kszabo16:09:56

well it’s not exactly what you asked for but Fulcro3's new template is a full CLJS SPA with all of the build tools above, just with Fulcro3 instead of re-frame: https://github.com/fulcrologic/fulcro-template

sjharms16:09:10

Thanks I will take a look! As a beginner its hard to compare and contrast the available options

kszabo16:09:11

sure thing, I would start with fulcro3 today, having developed multiple apps with re-frame, it’s way more framework-y, but it provides way more in return. See the docs for further info: http://book.fulcrologic.com/fulcro3/

👍 8
kszabo16:09:56

well it’s not exactly what you asked for but Fulcro3's new template is a full CLJS SPA with all of the build tools above, just with Fulcro3 instead of re-frame: https://github.com/fulcrologic/fulcro-template

thheller16:09:21

doesn't use deps.edn though

sjharms16:09:34

Thanks! I really like his courses (and purchased the reagent one), I was just trying to build up a list of steps to bootstrap up to his first lesson

thheller17:09:33

I guess you can use some of the templates like https://github.com/Day8/re-frame-template

sogaiu00:09:01

as a recent user of this feature i'm curious whether the resulting js would be dependent on the installed node version.