Fork me on GitHub
#shadow-cljs
<
2021-06-16
>
Franklin09:06:02

is it possible to do something like the following in shadow-cljs?

import './App.css';

Franklin09:06:47

mmmh... I wonder if there are any constraints/reasons why?

thheller09:06:05

well the constraint is that shadow-cljs knows how to build JS and CLJS files. adding support for CSS files would be a non-trivial amount of work.

thheller09:06:17

the reason I haven't done it is because I don't think it is useful

thheller09:06:22

I usually have a secondary build system for my CSS anyways and I can just put the import there. I think its silly to use JS constructs for that.

thheller09:06:04

for example you can use the setup described here

thheller09:06:39

and then either put your css in this file directly https://github.com/jacekschae/shadow-cljs-tailwindcss/blob/main/src/css/tailwind.css or have that import the other files

thheller09:06:48

I know that it would be more convenient if shadow-cljs handled all that automatically but I currently don't have the time/energy to work on that

Jakub Holý (HolyJak)10:06:26

Hello! I struggle with REPL-driven development with shadow. The problem is that when I define some troubleshooting / dev vars (such as (defn f [& args] (def *debug args) (...)) ), they tend to disappear. I suppose that is because I do most of my coding inside a (comment ...) and when IntelliJ saves the file after any changes, Shadow reloads the code. I thought that vars would survive that (as they do in clj) but it seems they do not, at least sometimes. Any tips? 🙏

thheller11:06:31

well yeah hot-reload and REPL are sort of at odds with each other

thheller11:06:58

hot-reload is not additive so it'll remove definitions that you only defined in the REPL

thheller11:06:15

so one option is to disable the hot-reload and just use the REPL like you would in CLJ

thheller11:06:30

or you keep the hot-reload but accept that stuff sometimes gets undefined

thheller11:06:43

technically it is all still there on the JS side, just the compiler doesn't know about it anymore

thheller11:06:39

things aren't additive with hot-reload since I want warnings to show up ASAP. say I changed (defn foo []) to (defn bar []). I want to see warnings for all places still using foo ASAP. In Clojure I often only notice such things when I restart my process a couple hours/days later since foo will still be around and valid until then.

raspasov12:06:16

Not sure if that’s relevant for you/shadow, but figwheel will actually refuse to load namespaces with warnings and namespaces that depend on them. That feels like a good default to me.

thheller12:06:30

same in shadow

thheller11:06:21

I guess I could compromise somehow and track which def was defined from a REPL and keep those instead of resetting the entire ns

Jakub Holý (HolyJak)12:06:10

Thanks a lot! Is there a quick way to switch hot-reload on/off?

Jakub Holý (HolyJak)12:06:51

(I agree that being non-additive to show such warnings ASAP is in general the better choice. I just need to find out an effective way of doing experiments/troubleshooting in the REPL - which may be telling intellij not to save files automatically.)

thheller12:06:03

from the CLJ REPL you can call (shadow/watch-set-autobuild! :app false)

❤️ 3
Proctor13:06:50

Hello.. I am relatively new to ShadowCLJS and using Clojure_Script_… and was wondering if you all might be able to point me in the general direction on JS libraries that use Node dependencies

Proctor13:06:27

there might be two issues going on: 1st - we are trying to use the Redlock library, and when we do as part of the require:

~   9             ["ioredis" :as Redis]
~  10             ["redlock" :as Redlock]

Proctor13:06:56

I get the following compilation error:

[:employee_record] Compiling ...
The required JS dependency "async_hooks" is not available, it was required by "node_modules/bluebird/js/release/util.js".

Dependency Trace:
        shadow/umd_helper.cljs
        user_auth_profile/employee_record/update.cljs
        user_auth_profile/system_config.cljs
        node_modules/redlock/redlock.js
        node_modules/bluebird/js/release/bluebird.js
        node_modules/bluebird/js/release/promise.js
        node_modules/bluebird/js/release/util.js

Searched for npm packages in:
        /Users/sproctor/guaranteed-rate/user-auth-profile/node_modules

See: 

Proctor13:06:46

The part that is confusing is that async_hooks is part of NodeJS

thheller13:06:12

which :target is your build? when building for the browser the native node packages are not available

Proctor13:06:21

a :node-library

Proctor13:06:37

we are deploying to AWS Lambda

thheller13:06:44

did you set :js-provider :shadow in your build config?

Proctor13:06:00

here is the build target:

:employee_record {:target :node-library
   43                             :exports {:update user-auth-profile.employee-record.update/-main}
   44                             :source-map false
   45                             :output-dir "target/employee-record"
   46                             :output-to "target/employee-record/lambda.js"
   47                             :compiler-options {:infer-externs :auto
   48                                                :externs ["externs/httpurr.js"]}
   49                             :js-options {:js-provider :shadow
   50                                          :keep-native-requires true}
~  51                             :release {:compiler-options {:optimizations :simple}}}

thheller13:06:32

so you can either not do that at all or add :keep-as-require #{"async_hooks"}

thheller13:06:23

note that I do NOT recommend using :js-provider :shadow for node builds

thheller13:06:57

better to keep the default and post-process with https://github.com/vercel/ncc or so if you really need things to be standalone

Proctor13:06:14

Is there some detail in the UserGuide that outlines this? Wondering if I have missed it, or mis-understood this

thheller13:06:27

:js-provider :shadow is built and optimized for browser builds. that is works for node was due to some experimental changes and I decided this wasn't worth doing so didn't continue working on it.

thheller13:06:05

so you likely found out about it in the github issue about this in the first place? the docs don't mention it

Proctor13:06:08

I have been trying to ramp up on ShadowCLJS as new projects at work are starting to use it over Figwheel for our AWS Lambda deployments

rberger21:06:35

I have a little playground example for getting cljs working with lambda. I think it still works https://github.com/omnyway-labs/lambda-play

rberger21:06:01

This also looks interesting. Not (yet) supporting cljs but it makes it easy to use Java, GraalVM or Babashka for lambdas https://github.com/FieryCod/holy-lambda The biggest issue I found with using cljs in lambdas (or probably any standalone node style program) is you are trapped in single thread / Promise / Async hell that you don't really experience in a browser / reagent / re-frame app

Proctor13:06:48

I saw some, but might have mis-understood what that issue was referring to

thheller13:06:16

I think its best to NOT post-process the files at all and just "deploy" your .js file together with the needed node_modules

thheller13:06:48

but I don't use AWS lambda so I don't know the details of how deploys actually work

Proctor13:06:40

got lost in the other references around MongoDB, and some other side threads on it… 😉

Proctor13:06:04

Thank you for your help!!!

Proctor13:06:44

need to take this back to the larger team and understand how we want to proceed

Proctor13:06:49

thanks again

kiranshila18:06:13

Is the story for having a library play nice with figwheel is to just provide the CLJSJS fallbacks? If so, how do I provide the equivalent :require calls?

thheller20:06:27

for people using figwheel with :target :bundle :require is exactly identical and no CLJSJS is needed

thheller20:06:09

for CLJSJS you need to setup that CLJSJS package and setup the proper :foreign-libs to emulate the :require

thheller20:06:16

in the code nothing changes

kiranshila18:06:54

As much as I'd like to slap a "won't fix/use shadow" tag on the issue haha

Jonathan19:06:21

@neo2551 did you ever figure out shadow-cljs with kamera?

David Pham19:06:36

Not really. What I did figure out though was to use Clojure dev tools protocols used in kamera to navigate to the page and make the screenshot and then use these screenshot with kamera.

David Pham19:06:51

Since I am using re-frame, I also had a list of events that cdp could use to go to the desired state.

Jonathan19:06:21

Thanks 🙂 I'm in a similar situation

Jonathan19:06:56

> use Clojure dev tools protocols used in kamera to navigate to the page Any chance you could elaborate on this?

Jonathan20:06:13

Kamera library looks fairly hackable, gonna try forking it. Will post more if it works.