Hi all, Is it possible to export macros to js context with the :esm target like this?
(ns core
(:require [cljs.spec.alpha :as s :include-macros true]))
(def exports #js
{:and s/and})
@namy.19 no. macros run at compile-time. you cannot use them dynamically at runtime unless you go full self-hosted. even then you couldn't use them from JS though.
is it possible to use annotation to skip the check? @thheller
which check? s/or
is a macro. you cannot call it dynamically from a function. what you are trying is simply not possible without eval
but this works
the s/and and s/def are both macros
it does not work. not in the sense of actually using spec correctly.
ok so it’s not possible..
macros are function that take CLJS syntax forms and return new CLJS syntax forms that the compiler will then compile. fundamentally you cannot call them from javascript without eval
and even with eval you'd be constructing the CLJS forms from JS and then compile them. not just call them as functions.
ok so if I want to use spec in js, i have to implement one in js
kind of yeah
really thanks for your super fast reply
@namy.19 you might find https://github.com/metosin/malli or https://github.com/plumatic/schema useful for these kinds of things
Any recommendations on how to handle environment-specific configuration? (e.g. hostnames that need to be different for dev vs different prod envs)
if you are talking about a browser build I recommend putting it into the HTML when this is dynamically generated HTML from a server
otherwise the typical answer is :closure-defines
Good idea, thanks
@thheller You once shared a neat code snippet to sidestep the closure “namespace has already been declared” thing. Can’t find it or remember where it was from. Are you able to reshare?
@mail024 https://github.com/thheller/shadow-cljs/blob/f28003cbb062fd27685048e8b4793eb05ca8f829/src/main/shadow/cljs/devtools/client/env.cljs#L145
Thanks!
Hi all. I was wondering if there was a way to make the cljs-runtime directory concatenate to a single file when we release? Using a Vercel and having the 1000 odd files on upload for every deploy kills thier hobby limit.
watch
or compile
produce the cljs-runtime
dir. release
does not and does not need it. it also doesn't clear it though. you can just rm -rf the-output-dir && shadow-cljs release app
or so yourself
the release build does that
hmm... so it does... I wonder where all those other files came from? thanks for you help!