This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-25
Channels
is there any way to get an export like this to work?
((fn []
(defn ^:export square [x]
(* x x))))
or do :export
ed vars always have to be top level?From the JS side of things, you have special syntax for a default
export.
// exporting same function two ways
export const foo = x => x
export default foo
// now either of these is valid to get at the same function
import { foo } from "./foo"
import alsoFoo from "./foo"
For ES5 transpiling, that default
just gets turned into a .default
property on the module. So I strongly suspect you can just export under the symbol default
from Cljs to get the same results for your JavaScript consumers?
And based on the https://clojure.atlassian.net/browse/CLJS-3235, I think you should also be able to get at that default from ClojureScript by appending $default
to the source location.
(require '["./foo$default" :as also-foo :refer [foo])
ah, that’s great info, in this case I wasn’t trying necessarily to do a default export
I had a macro that was bundling everything into a fn executed when some other code was ready;
this was causing defn
forms to run as side effects, but when they ran inside the (fn [] …)
the export wasn’t working
Oh yeah. I see. My answer was good-to-know, but totally missed the point of your question.
it was definitely good to know!