Fork me on GitHub
#shadow-cljs
<
2021-03-16
>
yqrashawn04:03:00

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})

thheller07:03:17

@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.

yqrashawn08:03:37

is it possible to use annotation to skip the check? @thheller

thheller08:03:40

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

yqrashawn08:03:44

but this works

yqrashawn08:03:36

the s/and and s/def are both macros

thheller08:03:21

it does not work. not in the sense of actually using spec correctly.

yqrashawn08:03:51

ok so it’s not possible..

thheller08:03:39

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

thheller08:03:04

and even with eval you'd be constructing the CLJS forms from JS and then compile them. not just call them as functions.

yqrashawn08:03:51

ok so if I want to use spec in js, i have to implement one in js

thheller08:03:54

kind of yeah

🥲 3
yqrashawn08:03:22

really thanks for your super fast reply

wombawomba10:03:34

Any recommendations on how to handle environment-specific configuration? (e.g. hostnames that need to be different for dev vs different prod envs)

thheller10:03:11

if you are talking about a browser build I recommend putting it into the HTML when this is dynamically generated HTML from a server

thheller10:03:04

otherwise the typical answer is :closure-defines

wombawomba11:03:37

Good idea, thanks

Alexis Vincent12:03:24

@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?

underplank23:03:23

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.

wilkerlucio23:03:47

the release build does that

underplank23:03:56

hmm... so it does... I wonder where all those other files came from? thanks for you help!

thheller08:03:51

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