Fork me on GitHub
#shadow-cljs
<
2021-08-13
>
alexdavis10:08:09

Is there a way I can build all cljs files in foo/*.cljs to an output-dir of bar/*.js? From reading the guide it looks like I have to explicitly specify every file/namespace symbol?

borkdude10:08:50

@alex395 Perhaps using :modules / code splitting? E.g. for nbb I have:

{:deps {:aliases [:test]}
 :builds {:modules {:js-options {:keep-as-import #{"fs" "module" "path"
                                                   "react" "react-dom"}}
                    :compiler-options {:infer-externs :auto}
                    :target :esm
                    :runtime :node
                    :output-dir "out"
                    :modules
                    {:nbb_core {:init-fn nbb.core/init}
                     :nbb_main {:init-fn nbb.main/main
                                :depends-on #{:nbb_core}}
                     :nbb_reagent {:init-fn nbb.reagent/init
                                   :depends-on #{:nbb_core}}
                     :nbb_promesa {:init-fn nbb.promesa/init
                                   :depends-on #{:nbb_core}}}
                    :build-hooks [(shadow.cljs.build-report/hook
                                   {:output-to "report.html"})]}
          :test {:target :node-test
                 :ns-regexp "-test$"
                 :output-to "target/test/test.cjs"
                 :autorun true}}}

borkdude10:08:09

and this outputs a nbb_reagent.js file and a nbb_promesa.js file

alexdavis10:08:23

but you have to specify the modules

alexdavis10:08:36

I want to infer them from the files that exist in a given pathe

borkdude10:08:56

write a script to generate the module configuration?

alexdavis10:08:09

Yeah... I was trying to avoid that 😄 I guess its fine though

borkdude10:08:55

but if you specify the main namespace of each directory which depends on the rest in that directory and nothing else depends on it, then it should work out with only specifying that one

alexdavis10:08:26

Hmm, just to be clear on what I'm trying to do, I have a nextjs project which transforms .js files that each have a default export function which gets turned into a lambda, and I want to write those .js files in cljs. So in my head I have a set of cljs/*.cljs files, and shadow will generate pages/api/*.js files for me, perhaps its not worth it and I should just learn javascript properly though...

alexdavis10:08:03

I saw this build hook which is maybe an approach I can use, though it hardcodes the export (I guess thats fine though?) https://github.com/thheller/next-cljs/blob/master/src/main/shadow/next_js.clje

alexdavis10:08:48

I guess the dream is for netlify/vercel etc to add support for bb/nbb 😄

tbrooke12:08:45

I am trying to use a library that apparently has a dependency of js-dom - I get 88 errors with shadow-cljs as follows: node_modules/jsdom/lib/jsdom/living/generated/AbortSignal.js:13 constructor is missing a call to super() Has anyone run into this ? Or know of a fix?

thheller16:08:31

what are you building? which build :target? jsdom typically runs in node but the error you get is from the closure-compiler processing the code, which is only done for browser builds?

Chris McCormick12:08:27

@tbrooke I have a library that depends on js-dom and it's successfully working with shadow-cljs, currently at version 16.4.0 of js-dom. What's the version there?

tbrooke12:08:51

@chris358 Thank I checked and it was using 15.2.1 - trouble is that it ie buried in a slew of dependencies - I’ll try to upgrade it or get it upgraded

emaun14:05:10

Hi 👋 currently facing this same issue - did updating the js-dom version to the latest work for you or was there another solution you landed on? 🙂

Chris McCormick13:08:51

If it says ^15.2.1 then you should be able to npm i js-dom@latest at the top level and it will use the updated version instead.

Chris McCormick13:08:01

I'm not sure if that will help though.

edo15:08:33

Hey everyone, I’m learning Clojure(Script). Been doing a cljs frontend using jacekschae shadow-cljs-tailwindcss boilerplate https://github.com/jacekschae/shadow-cljs-tailwindcss. I’m confused on how to deploy it to heroku :thinking_face: On one hand package.json already contains the release script and I get everything I need to serve it inside the public folder. But in this case I’d serve a node.js app. On the other hand I think it would be more clean to create a jar and use heroku java buildpack. I can’t find any beginner resource that explains this clearly. Can someone provide some hints? TIA. ❤️

lilactown15:08:42

not v familiar with heroku, but i would imagine that if you don't have a backend that heroku has a way of deploying a static site

edo15:08:17

Yeah, I’ve been able to deploy the backend because with lein is much easier. My confusion comes from this mix with shadow-cljs but I see what you’re saying. I don’t need to make it dynamic, i.e., serve it with node or java.

lilactown15:08:42

right. shadow-cljs is just a build tool that outputs JS files. you should be able to serve that via a static site w/o a backend

lilactown15:08:14

FWIW I use netlify for my static sites, they're cheap (free) and easy to deploy via a public or private git repo similar to what I remember heroku doing

lilactown15:08:45

if you're already invested in heroku that advice is probably not helpful tho 😄 sorry

edo15:08:51

Yeah I thought about that, but I already have a postgresql db and backend running on heroku :rolling_on_the_floor_laughing:

edo15:08:31

So I’d like to do this frontend deployment and as a next step deploy front+back together.

Ryan Jerue15:08:51

I’m not too familiar with heroku, but someone here did deploy something built with shadow to it recently https://clojurians.slack.com/archives/C6N245JGG/p1628542113248000 Vercel is also a pretty good (free!) tool to do this with. A now.json file like this was pretty useful https://github.com/rjerue/aoe2-facts/blob/release/resources/public/vercel.json

👍 3
lilactown15:08:46

I would look into that

👍 3