Fork me on GitHub
#clojurescript
<
2023-10-28
>
stagmoose01:10:02

what is the best way to read in a text file in cljs? i would like to use something like import raw from '../constants/foo.txt'; from https://stackoverflow.com/a/64788876 does the above line translate to (require '["../constants/foo.txt" :as data]) in shadow? i tried but it seems not working.

stagmoose02:10:43

i want code that not use "fs" from nodejs. or should i serve those data with http server, and use js/fetch instead?

hifumi12306:10:19

shadow.resource/inline

🙏 1
p-himik06:10:05

> should i serve those data with http server, and use js/fetch instead? Depends on the size of the data. For small files it's completely fine to inline them.

👌 1
henrik13:10:00

I tend to use macros to include static resources in CLJS.

henrik13:10:02

For your constants, for example, you could write a defconstant macro or similar.

stagmoose14:10:16

Thanks for everyone!

stagmoose14:10:48

@U06B8J0AJ does your macro use shadow.resource/inline ? or your implement our reading utils?

henrik14:10:10

No, I just use slurp or io/resource in the macro body, along with any transformation of the data that I need. Emit a def that contains the result.

🙏 1
stagmoose14:10:35

Cool! I didn't know i can use io stuff in cljs.

henrik15:10:40

You can in a macro, since those are compiled CLJ side.