This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-11
Channels
- # adventofcode (33)
- # babashka (1)
- # beginners (11)
- # biff (3)
- # calva (2)
- # cider (24)
- # clj-kondo (9)
- # cljfx (5)
- # clojure (39)
- # clojure-austin (2)
- # clojure-europe (11)
- # clojure-nl (1)
- # clojure-norway (22)
- # clojure-uk (10)
- # community-development (18)
- # data-science (24)
- # datahike (3)
- # events (3)
- # hyperfiddle (11)
- # lsp (22)
- # malli (3)
- # matrix (1)
- # off-topic (24)
- # other-languages (3)
- # overtone (7)
- # pathom (5)
- # reitit (2)
- # shadow-cljs (34)
- # sql (20)
- # squint (13)
If I would like a macro to do one thing for a shadow-cljs release, and another at dev time, what can I switch on? I’m guessing goog-define will only be accessible in the cljs, rather than the clj.
you can check (:shadow.build/mode &env)
. it'll be :release
for release builds and :dev
otherwise
Awesome! Thanks 🙂
(defmacro embed-image [image-path]
(if release-build? ;; *** How to define release-build?***
(let [image-bytes (io/file image-path)
base64-str (-> image-bytes
io/input-stream
IOUtils/toByteArray
Base64/getEncoder
(.encodeToString))]
(str "data:image/png;base64," base64-str))
image-path))
We use :closure-defines
like
:builds {:app {:dev {:closure-defines {goog.DEBUG true app.frontend.config/dev? true}}}}
and in app.frontend.config
(goog-define dev? false)
@U043RSZ25HQ I think this only works for the cljs bit, I needed access at clj/macro expansion time. But Thomas already answered. Thanks for your help!
The :none
optimized dev JS output from shadow is including this final line of:
SHADOW_ENV.evalLoad("shadow.module.main.append.js", false , "\nshadow.cljs.devtools.client.env.module_loaded(\x27main\x27);\n\ntry { my.app.here.client.app.main(); } catch (e) { console.error(\x22An error occurred when calling ()\x22); throw(e); }");
Where my.app.client.app.main()
is my main exported fn that initializes the app.
My “index page” also has a call to this same my.app.client.app.main()
in it - which I’d think would be normal.
The end result is that my init page is getting “double initialized” when navigating to the page the first time. This is problematic. What is the purpose of this SHADOW_ENV.evalLoad
call?evalLoad has absolutely nothing to do with it, evalload exists for this purpose https://clojureverse.org/t/improving-initial-load-time-for-browser-builds-during-development/2518, link is old and everything described has been default for many years. but the idea is still the same
:init-fn
in your build config is controlling this, basically it calls that function when the script is loaded
if you instead wish to keep it in the HTML, you remove :init-fn
and replace it with :entries [the.ns-that-had-init]
Ah yes, I had an :init-fn
. Sorry I was trying to use console.trace()
to figure out what was causing the “double call” and misdiagnosed.
How can I make my modules entry without an init?
:modules {:main {:init-fn my.app.here/main}}
Do I need something here at all?I cannot find this in the doc or online q&a that I’ve seen. Does shadow-cljs support hot reloading of clojure file changes? Similar to https://figwheel.org/docs/hot_reloading.html section “Reloading Clojure code”
Hmm. That may be problematic for me trying to transition from fig main to shadow. I’d have to think about how to deal with that.
As a progress report though I guess. I have got a large cljs project that uses webpack with :bundle
target and figwheel-main traditionally to have a working repl with shadow-cljs now.
I kept using webpack (via :js-provider :external
+ some hooks) for now to ease the transition and test things.
I think I have noticed consistently faster hot reloading for cljs at least. This was a main area of interest I had trying this. I haven’t explored releasing advanced output etc yet though. So I’d still have lots to do to really transition.
Yeah, I just have gotten so used to figwheel doing it, I never considered not having it.
I also work on clj-only projects though, and I don’t typically use any hot reloading watcher stuff for those. Funny enough.