Fork me on GitHub
#clojurescript
<
2020-03-24
>
Franklin06:03:53

How do I read files to strings in clojurescript, I need something like slurp.

Franklin06:03:17

I've seen this, https://gist.github.com/noprompt/9086232, but it doesn't make any sense to me, does it work?

hindol06:03:47

Are you targetting Node or browser?

mccraigmccraig06:03:31

in general @USWTQB9RU, yes the approach works - the file is read at compile time by the macro and substitutes a literal string for the value of project-clj

mccraigmccraig06:03:17

if you are using shadow then use shadow.resource/inline instead, for a cache-compatible approach

Franklin06:03:29

I've also seen this question asked in several other places online, but none give me a straight forward answer

dave20:03:58

hello! 👋 i'm running into some strange behavior, trying to use tools.deps to compile clojurescript => javascript in an existing project that i'm working on migrating from boot to tools.deps it was previously working via boot-cljs, and now i'm basically trying to detangle things and understand what's going on so that i can compile my clojurescript app in a simple, easy to understand bash script my setup is probably a little bit unusual because 1) i'm converting an existing project based on boot-cljs, (which, as i understand it, takes some liberties with cljs compilation), and 2) this is a hoplon application so, hoplon expects to find cljsjs.jquery on the classpath, and we ended up needing to use a newer version of jquery than the latest cljsjs one, so we've vendored the version of jquery we need into the project, and we have a deps.cljs that provides it as cljsjs.jquery:

{:foreign-libs [{:file "vendors/jquery/jquery.min.js"
                 :file-min "vendors/jquery/jquery.min.js"
                 :provides ["cljsjs.jquery"]}
                ...]}
the strange behavior that i'm running into is that this compiles successfully (in fact, it won't compile if i leave out the foreign lib entry above), but when i open the app in a browser, i get a JS console error from bootstrap saying it requires jQuery. when i look at the compiled JS file, i see other foreign libs' source at the top, but the jquery source is nowhere to be found i realize this is a lengthy and very specific problem, but does this happen to ring any bells for anyone here? any advice would be helpful a couple of related questions: 1. is there a difference between having a deps.cljs on your classpath vs. using the compiler :foreign-libs option? i couldn't find much documentation about deps.cljs, so i'm wondering if maybe i should be using the :foreign-libs compiler option instead (although i tried that and still ran into the same problem) 2. my script compiles clojurescript => javascript by invoking cljs.main with --compile-opts, --optimizations, etc. is that advisable compared to using cljs.build.api?

dave20:03:05

...aha. after posting all of that, i figured it out. in the new setup, i'm experimenting with the :modules feature, and i didn't realize that my index.html needs to include a script tag for cljs_base.js

👏 4