shadow-cljs

Shantanu Kumar 2025-05-05T11:24:44.939139Z

Hi, I have (in a UIx project) a assets/logo.webp file that I want to :require as ["logo.webp" :as logo]. I tried configuring shadow-cljs.edn as follows:

:js-options {:js-package-dirs ["node_modules" "assets"]}
This ^ doesn't work. Can anyone help me know if this is the right direction, or point at what am I doing wrong?

martinklepsch 2025-05-06T10:21:56.877359Z

whats the point anyway?I've often wanted to do this to inline SVG icons, when using SVG icons with , currentColor won't be picked up from document context for the SVG, which is a common pattern to set an icon's color. In Vite and other build tools there is stuff like svgr that converts SVG files to react components at build time (just sharing for context)

thheller 2025-05-06T11:06:32.563659Z

oh it is absolutely useful to have tools for assets. no doubt about that. doing it via require is the part I don't get 😛

thheller 2025-05-05T11:26:53.769429Z

there is no support for requiring "assets" that aren't actual CLJS/JS sources

thheller 2025-05-05T11:26:59.137029Z

so no images, video or css

thheller 2025-05-05T11:27:52.257199Z

whats the point anyway? just move it to public/assets/logo.webp and use /assets/logo.webp in your HTML (assuming public is your http root, might be resources/public)

Shantanu Kumar 2025-05-05T11:30:43.426149Z

OK, I am using ChakraUI and need to pass the logo as a React component property.

Shantanu Kumar 2025-05-05T11:46:33.760489Z

@thheller Thanks for the pointer - it worked by directly passing {:src "/assets/logo.webp"} as property after moving the logo file to public/assets/logo.webp.

cjohansen 2025-05-05T19:23:13.360079Z

I have a build that consists of several modules and some shared code. What's the best way to have separate dev and production entry points? Details in thread.

cjohansen 2025-05-05T19:24:33.555199Z

{:target :browser
 :modules {:shared {}
           :module1 {:entries [my.ns.mod1]
                     :depends-on #{:shared}}
           :module2 {:entries [my.ns.mod2]
                     :depends-on #{:shared}}
           ,,,}
 :dev {:output-dir "dev-resources/public/js"}
 :release {:output-dir "target/public/js"}
 :compiler-options {:externs ["datascript/externs.js"]
                    :source-map true}}
I'd like to have dev/myns/mod1.cljs as the entry point for :module1 during development, and prod/myns/mod1.cljs during production - or something along those lines. Do I have to duplicate all the modules to do this, or are there some other shenanigans I can employ?

cjohansen 2025-05-05T19:25:06.446399Z

It doesn't have to be classpath shenanigans, the important thing I want to achieve is to load one namespace with devtooling in development, and a leaner one in prod.

thheller 2025-05-05T19:25:26.037939Z

are these different source paths? dev and prod? they seem to have the same name? as in myns.mod1? or actual different namespaces?

cjohansen 2025-05-05T19:26:10.858199Z

In the suggestion above I was thinking different source paths. But I guess that's not strictly necessary.

thheller 2025-05-05T19:26:47.298129Z

and why do you want to switch them? wouldn't a closure define do to turn on extra "dev" behavior when needed?

thheller 2025-05-05T19:26:59.489829Z

or :preloads to inject extra dev only code?

cjohansen 2025-05-05T19:27:30.781629Z

Preloads sounds interesting!

thheller 2025-05-05T19:27:36.110459Z

switching :modules between modes is always going to be a bit verbose

cjohansen 2025-05-05T19:28:12.396449Z

Exactly. I'll look into preloads 👍

thheller 2025-05-05T19:28:59.634349Z

for example with shadow.grove I inject the devtools via preload https://github.com/thheller/shadow-cljs/blob/master/shadow-cljs.edn#L104

cjohansen 2025-05-05T19:29:47.801249Z

yeah, this is exactly what I want 👍