Fork me on GitHub
#clojurescript
<
2021-03-24
>
Max00:03:56

So, bit of an odd question: I’d like to use https://clojureverse.org/t/best-practices-for-importing-raw-text-files-into-clojurescript-projects/2569 (a macro that uses io and slurp) to inline a big JSON file into a cljs project. The inlining macro part works fine, but I’d also like to parse the file from JSON into clojure data structures/EDN at compile-time. That requires an external dependency, but only for clojure (not clojurescript) and only at compile-time. Is there a way to specify clojure compilation dependencies separately from clojurescript dependencies? A lot of the clojure JSON parsers rely on Java libraries and I suspect things would get mad if I specified them as normal clojurescript dependencies. I’m using shadow-cljs (I think that matters?)

p-himik00:03:50

Things won't get mad. :)

Max00:03:29

So I just mix it in with my normal clojurescript dependencies and everything will figure itself out?

p-himik00:03:56

If something somehow blows up, it would likely deserve a minimal reproducible example shared in #shadow-cljs

thanks3 3
thheller08:03:24

FWIW you should absolutely avoid inlining larger files into a build this way. the source compiled variant of edn will be much larger than the original edn and bloat your bundle size. ideally load data at runtime instead.

nilern08:03:58

Inlining the JSON string should be fine though?

thheller08:03:11

totally depends on the size. you don't want to inline 1mb of json. 1kb is fine.

nilern09:03:29

Depends on the use case also. Browsers have not been mentioned so it might be a toaster.

Max22:03:17

Good to know! In this particular case, I’m trying to create a single-html-file application to ease distribution of an application and I’m not actually serving it over the web, so size isn’t much of a concern. But it’s good to know that EDN compiles larger than the equivalent string. Thanks for the tip!

thheller08:03:44

yeah it would still be better to just inline the edn string and parse it at runtime

zackteo02:03:58

Are there any resources I can look at for how to integrate Clojurescript into a pre-existing JS codebase?

zackteo02:03:40

Specifically it is a React + Reframe codebase

zackteo02:03:28

Am doing a ClojureScript project for my final year project and will be discussing with my ex-colleague (doing my capstone project with a company I interned at) , how the integration pathway might be like if our work is something they want to integrate back into their js codebase

solf03:03:38

I don't have any personal experience doing that. If you're not using shadow-cljs, consider using it, and then this link could be useful: https://shadow-cljs.github.io/docs/UsersGuide.html#target-npm-module

zackteo04:03:32

Hmmm that seems to work :thinking_face:

zackteo04:03:27

I guess reagent components could be accessed via this too hmmm

zackteo09:03:49

How do I convert the lein template like lein new reagent myproject from lein-figwheel to figwheel-main ?

zackteo09:03:51

Also, does it make sense to use shadow-cljs as a compilation target and figwheel main as the repl type? I don't really understand where shadow fits into this

thheller09:03:55

no, you use either shadow-cljs or figwheel. not both. shadow-cljs also provides repl and hot-reload and so on

phoenixjj09:03:12

@zackteo - It would be easier to create project first then add figwheel-main as described in it's documentation.

phoenixjj09:03:08

or

lein new figwheel-main myproject -- --reagent

pmooser09:03:15

Is there a straightforward way to override toString on my records?

pmooser09:03:11

I found a message on the google group talking about this, but what is suggested seems to have no effect.

zackteo10:03:08

Oh :o right. Might something like this be a good starting point then ? https://github.com/lauritzsh/reagent-shadow-cljs-starter

zackteo10:03:02

Or maybe this https://github.com/jacekschae/shadow-reagent just that I should remove the proto-repl dependency :thinking_face: cause im using cider and my friends are using calva

nilern10:03:41

I find templates often just lead to more trouble because then I don't understand the build at all.

thheller10:03:13

agreed. I think everyone should go through a quickstart like tutorial at least once. be it cljs, figwheel or https://github.com/thheller/shadow-cljs#quick-start

thheller10:03:13

getting to know the parts involved is essential and templates often invite you to skip those parts just to get you going a little quicker. which in the long run isn't ideal IMHO