shadow-cljs

niwinz 2025-05-24T08:00:39.700329Z

Hey folks. Another question: there is a way to specify a custom subpath for loading modules (with shadow lazy loading)? I'm trying to setup an application under subpath, but i see that the lazy modules are loaded from /js/. But I want to load them from /prefix/js/. I'm pretty sure they follow the :asset-path "/js" on the configuration, but I wanted to ask if there is any other way. Would be nice to have this configurable on runtime; without that i need to make a custom build for each prefix and that is not very usable when distributing the already compiled application.

niwinz 2025-05-24T08:00:51.575829Z

In any case, thanks 😄

thheller 2025-05-24T14:04:40.026349Z

(:require [shadow.loader :as sl]) (sl/init "/prefix/js") some time before any modules are loaded

thheller 2025-05-24T14:05:24.452319Z

frankly nobody should be using this at all anymore and use :target :esm instead

thheller 2025-05-24T14:05:55.929799Z

but some of shadow.lazy utils still missing esm support, so I guess if you need that its not an option currently

niwinz 2025-05-24T19:08:19.546609Z

I'm not clearly understand that you saying. You mean we should not be using shadow.lazy? Our build is :target = :browser and we are using shadow lazy for load some collection of namespaces when a X page is required. I want to make the application to be able to start and work correctly under a prefix and not depend on the :asset-path build option.

niwinz 2025-05-24T19:09:30.340959Z

You are suggesting that we should target esm instead of browser? for our web application?

thheller 2025-05-25T05:42:22.225159Z

:browser is fine, but :esm has certain advantages when it comes to lazy loading. :browser requires the whole closure loader stuff, while :esm can just use the built-in native browser import()

thheller 2025-05-25T05:43:06.471949Z

esm is also a browser built-in standard for a decade or so, so it has other advantages too just from that

thheller 2025-05-25T05:44:36.078299Z

for example the files you are importing in esm can just use ./that-module.js as path, since the path resolves relative to the current JS file. so no custom prefix is required

thheller 2025-05-25T05:45:03.333559Z

this doesn't work for the current loader stuff since that path is relative to the current html file

thheller 2025-05-25T05:45:33.314029Z

I've been lazy myself and have not switched to :esm for all my stuff yet, but I feel its time 😛

niwinz 2025-05-26T19:36:51.771689Z

Very interesting. Thanks for explanation i will try to make an experiment on migrating all to esm.