This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-23
Channels
- # announcements (11)
- # architecture (14)
- # babashka (34)
- # bangalore-clj (8)
- # beginners (108)
- # calva (10)
- # cider (19)
- # circleci (9)
- # clj-kondo (19)
- # clojars (4)
- # clojure (62)
- # clojure-australia (2)
- # clojure-europe (62)
- # clojure-italy (14)
- # clojure-nl (8)
- # clojure-poland (1)
- # clojure-spec (14)
- # clojure-uk (59)
- # clojurescript (14)
- # community-development (5)
- # conjure (2)
- # core-async (10)
- # cryogen (1)
- # cursive (11)
- # data-science (1)
- # datahike (13)
- # datomic (21)
- # deps-new (4)
- # ethereum (1)
- # events (4)
- # fulcro (34)
- # helix (2)
- # jobs (2)
- # juxt (33)
- # kaocha (4)
- # lsp (18)
- # malli (4)
- # membrane (2)
- # off-topic (23)
- # re-frame (3)
- # reitit (4)
- # remote-jobs (1)
- # reveal (6)
- # shadow-cljs (47)
- # slack-help (2)
- # spacemacs (5)
- # sql (45)
- # startup-in-a-month (6)
- # testing (4)
- # tools-deps (21)
- # xtdb (4)
Hi, we're creating a lib compiling to jvm & js. If I create a clj-lib I can put some commonly used resource files in my classpath and load them at execution time. Is there a way to achieve a similar behavior in cljs? E.g. load & inline these files at compile time?
Artifacts will be published to clojars, npm & be used in browser.
If you're using shadow-cljs, there's a built-in function for that: https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745 If you're using some other build tool, you can just copy the source of that function to your project (check the license first though).
cool, exactly what I looked for. Fortunately we're using shadow-cljs - thanx :-)
I am having trouble using eval, getting lots of undeclared var warnings, and I THINK the problem is that I have not configured something like the env/default-compiler-env correctly. I think this because if I look at the return of (empty-state), it is very empty, with almost no namespaces.
Shoot. I wasn't finished... In contrast, when I walk through this tutorial (https://yogthos.net/posts/2015-11-12-ClojureScript-Eval.html), I see that (empty-state) provides lots of namespaces, including much from cljs.core, and this works for me. But, when I copy the code into my project, it does not work, and I notice (empty-state) has almost nothing in it. The undeclared vars include things like fn, +, -, * and my local vars too. E.g. the eval of the read-string of "(fn[x] (+ x 2))" triggers several undeclared vars. This is the code from http://yogthos.net post that I put in my project...
(ns cljs-eval-example.core
(:require ...
[cljs.tools.reader :refer [read-string]]
[cljs.js :refer [empty-state eval js-eval]]))
(defn eval-str [s]
(eval (empty-state)
(read-string s)
{:eval js-eval
:source-map true
:context :expr}
(fn [result] result)))
Shoot, again. I just habitually hit <Return> and fire my message before I am done.... Anyhow, the difference in tutorial code vs mine includes fact that it was started with "lein new reagent" and mine with luminus re-frame. I start the REPL in the tutorial with figwheel whereas I am using shadow-cljs. Any tips on what is involved in getting (empty-state) to return an environment that can support evaluating functions that do basic math like +,-,*,/,log,abs,etc. would be very appreciated.
Evaluating CLJS in a browser requires a build with self-hosting capabilities. AFAIK, even these days it's still a finicky and not that well documented thing - not that many need that functionality, especially given that it inflates the bundle size. With that being said, it's no surprise that you can't get it working when you use a different template, a different build tool, and a different way to start REPL.
using the self-hosted stuff with shadow-cljs requires doing this: https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html
Thanks @U05224H0W and @U2FRKM4TW! This advice will save me lots of wasted time on my misdirected ideas and points me towards several ideas. I am not sure which is best yet, but I think the self-hosted ClojureScript compiler (great job on the blog!) will work, as would a request to back-end Clojure eval. I also remembered I've used instaparse withe some macro processing. That might work fine for supporting a small set of math operations. Thanks again!
another option might be using sci (https://github.com/borkdude/sci)