Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
edited by

Why doesn't clojure have reader conditional for nodejs and browser? They are very different environments with different utilities and libraries.

Currently I'm doing this

#?(:cljs (def is-browser
           (exists? js/window)))
#?(:cljs (if (not is-browser)
           (require 'http)))

Is there a better way?

1 Answer

0 votes
by

It's a open problem in clojurescript (maybe in JS itself?)

shadow-cljs allow you to define custom conditionals

https://shadow-cljs.github.io/docs/UsersGuide.html#_conditional_reading

then you can do
(def browser? #?(:node false :cljs true))

...