Fork me on GitHub
#shadow-cljs
<
2022-08-31
>
zhuxun200:08:15

How viable is it to use shadow's clojure APIs directly as opposed to using npx shadow-cljs ? Does the NodeJS API do a lot of magic (middleware, etc.) in addition to calling (server/start!)?

zhuxun200:08:11

What's the minimum Clojure code to replicate the exact behavior of npx shadow-cljs server?

thheller06:08:30

to get the exact behavious of server you just have (server/start!). thats all as far as the shadow-cljs build server is concerned

thheller06:08:54

however the "connect to server" part of the node shadow-cljs command cannot really be replicated

thheller06:08:34

so you probably want to do all other stuff over the REPL or UI and now use further CLI command to start a watch for example

just.sultanov11:08:51

Hello, @thheller. Could you help me, please. I’m working on migrating from figwheel-main to shadow-cljs and unfortunately I can’t change the structure of the project. I have a backend module that serves my static files via /static route, and I have a frontend module that compiles js to the backend resource directory backend/resources/public/frontend2/assets/js. I don’t have a file index.html - the server generates it itself. JS files are reloaded correctly, but I have some problems with reloading resources (CSS). Any changes to CSS files are not handled. I have a webpack configuration that compiles less files to the backend resources directory /backend/resources/public/frontend2/assets/bundle.css I added the parameters :watch-dir and :watch-path, but it didn’t help.

[:link {:rel "stylesheet", :href "static/frontend2/assets/bundle.css", :type "text/css"}]
[:script {:src "static/frontend2/assets/js/app.js", :type "text/javascript"}]
:app  {:target     :browser
       :output-dir "../backend/resources/public/frontend2/assets/js"
       :asset-path "static/frontend2/assets/js"
       :modules    {:app {:init-fn frontend.core/-main}}

       :devtools   {:preloads  [devtools.preload]
                    :watch-dir "../backend/resources/public/frontend2/assets"
                    :watch-path "static/frontend2"}
Thank you!

thheller12:08:52

@just.sultanov what is the path you include to css in the html?

thheller12:08:42

I'm guessing its :watch-dir "../backend/resources/public" but can't say exactly without known the paths

thheller12:08:25

(meaning why is the path in that html relative? what is the path of the page you are calling?)

thheller12:08:43

[:link {:rel "stylesheet", :href "/static/frontend2/assets/bundle.css", :type "text/css"}]?

just.sultanov12:08:10

Backend generates the following paths:

[:link {:rel "stylesheet", :href "static/frontend2/assets/bundle.css", :type "text/css"}]
[:script {:src "static/frontend2/assets/js/app.js", :type "text/javascript"}]

thheller12:08:19

then its :watch-dir "../backend/resources/public/frontend2" and :watch-path "static/frontend2"

thheller12:08:44

or :watch-dir "../backend/resources/public" and :watch-path "static"

thheller12:08:49

the blog post explains this I hope

just.sultanov12:08:19

Yes, the path to static files is relative. This is provided by the compojure context. Well, thank you. I will try to use absolute paths

thheller12:08:05

thats fine, just makes it harder to answer the question without knowing the full exact paths 😉

🙏 1
migalmoreno18:08:14

Hi, new to shadow-cljs and CLJS in general. I've tried out both figwheel-main and shadow-cljs in some learning projects with basic configurations, and I've noticed that when using figwheel, I can get completions for goog.dom functions in a CIDER REPL by simply typing "goog.dom/...", while I don't get auto-completion in shadow-cljs builds for vars in that namespace. Is this related to this issue https://github.com/thheller/shadow-cljs/issues/834 ?

thheller18:08:47

not a clue how cider autocomplete works so can't say

mkvlr19:08:25

is there an alternative to nuking .shadow-cljs when a https://github.com/babashka/sci/blob/133a7565749ac6cd5a8308182f0b1c7fc47e8a3d/src/sci/impl/namespaces.cljc#L53-L64 depending on the contents of an env var? Maybe a way to whitelist env vars that shadow can take into account for caching?

mkvlr19:08:10

or is there a way to rewrite this macro so it plays well with shadows caching?

borkdude19:08:51

so, delete the cache file for that macro-related ns

thheller19:08:23

could store it there and get it out of the (get-in @cljs.env/*compiler* [:options :external-config :whatever-you-added]) during compilation

mkvlr19:08:19

shadow does a lot better in cache invalidation regarding macros than the regular cljs compiler, correct? But reading from the env will fail bust its caching strategy?

thheller19:08:38

yes, it does not check the env

thheller19:08:02

basically it checks all the options above + the files involved in the compilation

thheller19:08:12

thats all it looks at

mkvlr19:08:13

ok, have you considered being able to signal (maybe via metadata) on a macro var that it should not be cached or does that not make sense?

thheller19:08:16

well to know if it can use the cache it must be able to derive it from only the file and compare before compilation

thheller19:08:43

I guess there could be some way for a macro to signal "hey, please don't cache this file"

thheller19:08:03

if cache is never written it can never be read

mkvlr19:08:30

ah so the cache is on a file level, not on the level of vars?

mkvlr19:08:22

@isak nope, wasn’t aware of this, thanks!

1
thheller19:08:04

that also works yes