This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-18
Channels
- # adventofcode (12)
- # asami (2)
- # babashka (95)
- # beginners (17)
- # biff (5)
- # calva (1)
- # clojure (90)
- # clojure-europe (15)
- # clojure-nl (1)
- # clojure-norway (8)
- # clojure-uk (6)
- # clojuredesign-podcast (2)
- # clojurescript (34)
- # clr (1)
- # community-development (42)
- # cursive (11)
- # data-science (1)
- # datomic (13)
- # graalvm (5)
- # hoplon (2)
- # hyperfiddle (32)
- # off-topic (1)
- # pathom (6)
- # releases (1)
- # shadow-cljs (25)
- # squint (4)
- # xtdb (10)
Hi! Is there a way of customizing goog-define vars per modules?
Currently if we want to customize a value per build, we can add to lets say websocket.cljs file something like (goog-define port 7722)
and then for each build do :
:builds
{:my-app {... :compiler-options {:closure-defines {websocket/port 7722}}
:web-worker {... :compiler-options {:closure-defines {websocket/port 7733}}
but looking at shadow-cljs UserGuide looks like the recommended way of https://shadow-cljs.github.io/docs/UsersGuide.html#_web_workers is with a different module under the same build. Is there a way of customizing stuff for each module?and no, this is not possible as they are compile time constants that can only have one value
why not just use two different defines?this is because that websocket/port thing is tooling configuration. I would like different builds to connect to different instances of the tools, which is possible with closure-defines, but not when compiling to separate modules. So this "websocket" namespace is the same for all builds/modules and coming from a library, but I want to be able to setup it differently for the main app and the web-worker for example
@U05224H0W is there a way of having different preloads for your app and web-workers when building this way?
you can just make a separate build for the worker if you wish. it'll just be more JS for the user to download
nice, thanks!
I want to have a macro that "lifts" a definition (a static constant) into the top-level. Is this currently possible with the default CLJS compiler or shadow-cljs?
basically shadow just binds this var when it compiles shadow.build.compiler/*analyze-top*
which is just a function taking a form to analyze, and the result being "prepended" at the top
this looks similar to what I want to do. I want to take something like
(defn foo []
($ :div ($ :span ($ :text "foo"))))
and generate
(def tmpl01
(doto (js/document.createElement "template")
(-> (.-innerHTML) (set! "foo"))))
(defn foo []
(.. tmpl01 -content -firstChild (.cloneNode true)))
(<< [:div [:span "foo"]])
creating (def the-thing ...)
at the top level and (the-thing ...)
where it was used
so IIUC I can just call shadow.build.compiler/*analyze-top*
in my macro with the code I want and it will add that to the top of the file?
(defn foo []
(<< [:div [:span "foo"]]))
;; generates
(do (def the-thing (create-the-thing))
(defn foo []
(the-thing)))
https://ask.clojure.org/index.php/8879/cljs-should-macros-support-lifting-vars-to-the-ns-level š
Hello everyone. On a shadow-cljs
project Iād like to have some tests run whenever I reload any of my namespaces:
Like this:
(defn ^:dev/after-load autoload! []
(js/console.log "== Autoload entry point ==")
(let [test-results (with-out-str (my.test-runner/run-tests))]
(if (str/includes? test-results "FAIL")
(js/console.error test-results)
(js/console.log test-results))))
I have added my.test-runner
to the :devtools :preloads
vector. But I am having trouble on CI, when the code should not run at all. Is there a way around this?
I am using preloads
with the aim of avoiding including this namespace on the production build.Yeah, CI runs that way, what I would like is to somehow remove that code, or to know if there is way to only run this code on dev.
but not the autoload! function. Sorry for the confusion. But I guess I can move that to a preload.
Thanks