Fork me on GitHub
#clojurescript
<
2018-06-17
>
Rina12:06:41

Hi I want to compile my clojurescript code into a js library, and use as an external library in another pure JS react application What do I need to add to my lein options in order for me to be able to use the cljs code as a module? (`export` and import) way

burhanclj12:06:43

@rinam I think you can just call any public function with proper namespace.

Rina12:06:09

Right, it works

Rina12:06:25

But I want to use it in a webpack

Rina12:06:39

import ... from way

burhanclj12:06:06

There seems to be ^:export metadata that you can use on the function. I never done it though.

Rina12:06:48

That's used for calling the functions with the namespace even when the file is minified

dnolen13:06:06

do what you would do in JS, we don’t provide any specific support for that use case

dnolen13:06:11

You’ll need to use whatever export pattern the JS tools expect

Rina13:06:17

I don't want to have to do it manually every time I make changes and compile my clojure library

lilactown16:06:09

shadow-cljs provides a build target that does a lot of the work for you: https://shadow-cljs.github.io/docs/UsersGuide.html#target-npm-module

lilactown16:06:32

it requires switching to using shadow-cljs instead of the standard cljs compile toolchain tho

Rina11:06:22

Thanks, that was very helpful

dnolen13:06:44

I don’t understand how it would be more manual than what you would do with a JS library?

dominicm16:06:14

I'm trying to use cljs.js/eval, but running into cljs.core not being loaded. Is there something special needed to bootstrap clojurescript itself into cljs.js/eval?

dominicm16:06:46

Doing the string "(+ 2 2)" is giving "Use of undeclared var cljs.user/+"

dominicm17:06:59

Apparently shadow-cljs operates a little differently in the bootstrap context 🙂

mfikes17:06:15

@dominicm + should come with (cljs.js/empty-state). A small example is on this page https://clojurescript.org/community/reporting-bootstrap-issues

lilactown18:06:06

so in trying to capture derefs using @, I ended up writing a macro that just replaces clojure.core/deref with another symbol 😛

lilactown18:06:10

lisp makes it so wonderful to create footguns

😆 4