This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-15
Channels
- # announcements (10)
- # asami (5)
- # babashka (49)
- # babashka-sci-dev (8)
- # beginners (25)
- # calva (98)
- # cider (2)
- # clj-kondo (22)
- # clojure (32)
- # clojure-dev (12)
- # clojure-europe (32)
- # clojure-nl (3)
- # clojure-spec (3)
- # clojure-uk (10)
- # clojurescript (12)
- # community-development (1)
- # conjure (71)
- # cursive (7)
- # datalog (6)
- # events (2)
- # figwheel-main (2)
- # fulcro (4)
- # jobs (2)
- # kaocha (3)
- # lsp (43)
- # membrane (12)
- # missionary (9)
- # off-topic (61)
- # pathom (7)
- # polylith (2)
- # reagent (38)
- # remote-jobs (4)
- # shadow-cljs (17)
- # specter (1)
- # tools-deps (38)
- # vim (51)
- # web-security (5)
Is it possible to write a macro that will emit code (or not emit code) based on the value of a goog-define
? I'm trying to figure out whether I can have a debug macro that basically disappears in production builds.
devcards from bruce work in this fashion: • the check: https://github.com/bhauman/devcards/blob/master/src/devcards/util/utils.clj#L4 • usage in a macro: https://github.com/bhauman/devcards/blob/master/src/devcards/core.clj#L127
I'm trying to use :reader-features
to conditionally execute some top-level code (basically #?(:my-feature (reset! my-atom :my-value))
) at the start of a namespace in a library I'm including my build (in order to control how a few macros work), but this code doesn't seem to actually get executed at compile time.
Is this intended, and if so, is there some other way to get build-specific compile-time configuration into a library?
@pmooser @wombawomba you can write macros that access the cljs.env/*compiler*
atom. that has an :options
key which is :compiler-options
from the build config. so you can set stuff there and do conditional stuff in the macro
@wombawomba yes, as the :reader-features
name implies it happens at read time. so emitting them in a macro is not possible
Got it, thanks!
To clarify, though, I'm not trying to use reader conditionals to emit anything in a macro — rather I'm trying to conditionally set some state before defining my macros.
...the problem with my approach, though, is that the code is getting loaded in clojure, so only :clj
reader conditionals end up getting evaluated.
Actually, I think the easiest way to handle this for me would be to use Java properties (I'm already using these to do something similar when building the same library via GraalVM).
Good to know.
So I tried this out (I'm using shadow-cljs with leiningen, so I just set :jvm-opts
in my project.clj
) and it seems to work — just one problem: I only want this behavior sometimes. Is is possible to control whether the property is set or not from the command line?
(It seems I can set a leiningen profile in my shadow-cljs.edn
, but I can't see how to control which profile gets applied when invoking shadow-cljs
)
To answer my own question: I was able to make it work by setting JAVA_OPTS
. (It initially seemed like it wasn't being picked up by leiningen, but that was because I'd made a mistake).