Fork me on GitHub
#shadow-cljs
<
2021-02-07
>
Luis Santos14:02:56

Hi everyone, Whats the recommended way to use static assets installed via npm? Let's say that I want to install bootstrap or tailwindcss using CSS and I want the assets to be available int he public folder and later in the dist folder. What are the best practices?

thheller15:02:06

I just use tailwind with postcss as described in the tailwind docs

👍 3
aratare15:02:12

Hi there. I'm combing through the doc and there doesn't seem to be any way to tell shadow-clj which lein profile to use dynamically instead of having it hardcoded inside shadow-cljs.edn? The reason for this is I have multiple lein profiles, each of which corresponding to different environment like dev, test, prod, etc. and I'd like shadow-clj to be able to do the same. Would appreciate any insight. Thanks in advance 🙂

thheller16:02:04

shadow-cljs does not support this and it usually isn't required for CLJS. at least I haven't heard a convincing argument for it yet 😉

thheller16:02:27

you can just use lein if you really must

thheller16:02:47

instead of shadow-cljs release app you do lein with-profiles +whatever run -m shadow.cljs.devtools.cli release app

aratare18:02:17

Thanks a lot 🙂 I'm not sure if it's technically hard to do but having separate lein config inside each build would be nice for something like this I imagine.

thheller20:02:53

the way things currently work this is not possible and I have no interest in changing it. if you must do this you can just use lein as described.

coby20:02:09

I'm having an adventure failing to understand how to connect my editor (Neovim/Conjure) to a REPL for a :target :node-script build. So first I'm doing shadow-cljs start && shadow-cljs clj-repl app and then running (shadow/watch :app) and (shadow/repl :app) from there, per https://shadow-cljs.github.io/docs/UsersGuide.html#_nrepl_usage. The prompt then changes to cljs.user=> and when I evaluate forms directly from there it complains "No application has connected..." which is to be expected I think since I haven't actually started a Node process. So far so good I guess. However, at this point when I do :ConjureConnect 7001 from my editor and try to evaluate forms, it is connecting to a plain Clojure REPL and doesn't consider JS forms e.g. (js/console.log ...) valid. I think this is because the (shadow/... :app) forms only transform that one client connection into a CLJS REPL; the nREPL server itself is still in Clojure "mode"...but how do I get the server itself to compile CLJS forms?

thheller20:02:17

@ctamayo first of all are you sure shadow-cljs node-repl isn't enough for your use case? second if you connect to the nrepl that connection starts out in CLJ mode. so you switch it via (shadow/repl :app)

thheller20:02:52

the server is always in CLJ mode and that cannot be changed. you just switch your connection when needed.

3
coby20:02:49

When I do shadow-cljs node-repl it starts up the server on 7001 but when I do :ConjureConnect 7001 it complains:

[2021-02-07 12:53:39.022 - WARNING] :shadow.cljs.devtools.server.nrepl-impl/init-ns-ex - {:init-ns }
FileNotFoundException Could not locate media_server/app__init.class, media_server/app.clj or media_server/app.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
My main file is src/media_server/app.cljs and when I change it to .clj it complains that the ns form does not conform to spec because I'm trying to require the "fs" node module.

thheller21:02:23

sorry I can't answer conjure questions. I have never used it and have no idea what it does.

coby21:02:33

It's a REPL client for Neovim, no worries :thumbsup::skin-tone-3:

thheller21:02:09

I know what it is. I just don't know what it does on connect and stuff

thheller21:02:50

looks like its trying to change the CLJ connection to that ns. that will not work, it needs to be switched to CLJS first

thheller21:02:35

think of shadow-cljs as a CLJ server only. it then takes commands to build CLJS. you cannot eval CLJS without giving those commands first

thheller21:02:30

for the node-repl you can just run shadow-cljs server .. connect to nrepl and then run (shadow/node-repl)

coby21:02:46

Yeah, I immediately remembered I hadn't done that, sorry. Here's what happens when I do though.

$ shadow-cljs node-repl
shadow-cljs - config: /home/tamayo/projects/media-player/server/shadow-cljs.edn
shadow-cljs - server version: 2.9.6 running at 
shadow-cljs - nREPL server started on port 7001
cljs.user=> (shadow/watch :app) ;; <----------- TRYING TO SWITCH MODES HERE ----------<<<<<
------ WARNING - :undeclared-ns ------------------------------------------------
 Resource: :1:2
 No such namespace: shadow, could not locate shadow.cljs, shadow.cljc, or JavaScript source providing "shadow"
--------------------------------------------------------------------------------
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: :1:2
 Use of undeclared Var shadow/watch
--------------------------------------------------------------------------------
TypeError: shadow.watch is not a function
    at cljsEval (<eval>:1:16)
    at global.SHADOW_NODE_EVAL ([stdin]:105:10)
    at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:24:1)
    at ret (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:49:13)
    at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:120:11)
    at Object.shadow$cljs$devtools$client$node$repl_invoke [as repl_invoke] (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:47:1)
    at shadow$cljs$devtools$client$node$process_message (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:106:5)
    at /home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:242:9
    at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:194:7)
    at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] (/home/tamayo/projects/media-player/server/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:248:7)
cljs.user=>

thheller21:02:47

or shadow-cljs server ... connect nrepl then (shadow/watch :app) and (shadow/repl :app)

thheller21:02:22

if you run shadow-cljs node-repl in the command line that will drop you directly into CLJS mode as indicated by cljs.user=> prompt

thheller21:02:31

but ONLY that command. not the nrepl server

coby21:02:53

only that command meaning only that connection/client?

thheller21:02:19

listen. kill all processes. run shadow-cljs server.

thheller21:02:33

that starts a blank server that just does nothing except wait for further commands

thheller21:02:47

THEN connect nrepl or run other commands in a separate terminal

thheller21:02:43

you can use the shadow-cljs commands or you can run all those directly over nrepl

thheller21:02:52

just don't confuse the two and their purpose

thheller21:02:39

sorry for making this more confusing by bringing up node-repl. that is just a simplified node repl that is already ready to go with its own node process but not coupled to any build

thheller21:02:56

vs :node-script where you have to manage the node process yourself

coby21:02:58

> not coupled to any build I see, that is the piece I was missing. I understand the piece about server vs the various REPL commands...I tried various ways but still can't get my editor REPL to play nice with CLJS. So I need to just figure out what the issue is on the Conjure side. Sorry if it seemed like I wasn't listening, I was just trying to validate my understanding.

thheller21:02:38

so you get an error if you run shadow-cljs server and then connect conjure? without doing anything else?

thheller21:02:37

that shouldn't happen but if it does its on the conjure side of things

thheller21:02:51

unless you maybe configure :nrepl {:init-ns ...} in your shadow-cljs.edn config?

coby21:02:32

Ah, I did do that, now I understand why it wouldn't like that...

coby21:02:23

and yes, it errors at that point w/o anything else

thheller21:02:48

right yeah. that would switch the CLJ nrepl to that ns but since its a CLJS ns that doesn't work

thheller21:02:06

you switch the default ns for you build via :devtools {:repl-init-ns foo.bar} in your build config instead

coby21:02:25

gotcha, that makes sense

genekim23:02:56

I’m using shadow-cljs on an M1 MacBook Pro for a couple of week. (PS: it’s amazing. IntelliJ/Cursive, shadow-cljs watch, kaocha watch, Fulcro RAD app running in browser. Laptop stays cool, totally silent, and runs for hours with only 20-30% battery consumed. So different than my Intel MBP, which would last for no more than 45m!) But I have noticed something strange, and don’t know how to best document this strange behavior. When using an ARM JVM (either IntelliJ JBR or Azul JVM), it seems to take much longer to detect file changes. This affects the shadow-cljs builds, and kaocha watch tests. When a save a file, it may take between 3 seconds and maybe even up to 10+ seconds for the file change to trigger a compile or test run. Has anyone else run into this problem? Is there a simple test case or scenario I can use to isolate what is causing the delay? (I haven’t tried using an x86 JVM yet. I’m sufficiently afraid I’ll permanently break my dev setup by doing that… Unwarranted I’m sure, but… 🙂

thheller23:02:18

@genekim I assume this is on Big Sur so try the latest version. I removed the old hawk file watching lib which seemed to cause trouble on Big Sur

🤯 6
genekim23:02:56

Incredible, @thheller. Thank you!! Always blown away by shadow-cljs , and how it makes the build system just fade into the background, in the best possible way! 🎉🎉🎉 So wonderful!

❤️ 9
thheller23:02:31

don't know anything about how it affects M1 though. only had reports from older hardware but all related to big sur so maybe the same on M1

genekim23:02:47

Will try this right now!

thheller23:02:43

you can also set :fs-watch {:hawk false} in shadow-cljs.edn top level on older versions, basically the same effect

genekim23:02:58

Confirmed that file watcher issue seems to have disappeared. Thanks, @thheller!!

👍 6