shadow-cljs

witek 2025-01-29T12:01:26.670379Z

Given a :browser build. How can I use a module from a remote server? Can I have the following in my HTML:

How can I use or require automergerepo in my ClojureScript code?

thheller 2025-01-30T08:31:13.870709Z

> (:require ["https://...."]) didn't work, because the remote code is not Google Closure compatible.

thheller 2025-01-30T08:31:40.114119Z

that is completely irrelevant? google closure never sees it? it just emits a literal import * as automerge from "https://..."?

thheller 2025-01-30T08:32:32.880379Z

no clue if node has something similar to importmaps, but node can just load the thing probably. and for node targets by default shadow-cljs does not bundle dependencies, so again closure would not ever see automerge. so as long as node can load the thing you likely do not need to do anything

thheller 2025-01-30T08:34:08.944679Z

if you are using :target :esm with node you should set :js-options {:js-provider :import} https://shadow-cljs.github.io/docs/UsersGuide.html#_third_party_tool_integration, otherwise :esm will try to bundle

thheller 2025-01-29T15:56:35.971599Z

you have several options, best bet is probably using :target :esm instead

thheller 2025-01-29T15:57:26.600369Z

there you can just do

(ns my.app
   (:require ["" :as automerge]))
without the import map

thheller 2025-01-29T15:58:18.525349Z

or you keep the import map and (:require ["automergerepo" :as automerge]) but then in the build config set :js-options {:keep-as-import #{"automergerepo"}}. that'll tell shadow-cljs to not bundle that require and instead let it load at runtime

witek 2025-01-29T16:06:34.407179Z

Thank you!

witek 2025-01-29T23:23:10.105829Z

I switched to :target :esm. (:require ["https://...."]) didn't work, because the remote code is not Google Closure compatible. So I went with the import map and it works fine in the browser. Now I want to run the same code in node. But how do I specify the import map? So that my (:require ["automergerepo" :as automerge])` is resolved to the remote URL and loaded?

Ken Huang 2025-01-29T16:16:58.090489Z

Hey guys, is there a way to reload a hook definition in shadow-clj? Currently, I just restart the REPL to make it possible, which is tedious. (I define hooks in a separate build.clj file)

thheller 2025-01-30T08:24:37.507559Z

why would that need to be a hook? what does it use from the build-state map the hooks receive? if nothing it doesn't need to be a hook

thheller 2025-01-30T08:25:07.510609Z

also with manifest v3 I saw no need to generate the file at all anymore?

Ken Huang 2025-01-31T02:45:23.259329Z

The reason why I used a hook is that I need to use different configs between dev and prod, and using Clojure forms is more compact in general.

thheller 2025-01-29T16:18:01.427789Z

my general answer is: you probably shouldn't be using hooks in the first place 😛

thheller 2025-01-29T16:18:29.632149Z

other than that it is just clojure code. So I'd work on it at the CLJ REPL.

thheller 2025-01-29T16:23:01.248149Z

(require 'build :reload) will reload it at the REPL, or the usual load-file. the usual REPL stuff

❤️ 1
thheller 2025-01-29T16:23:59.708309Z

you can trigger a rebuild from the REPL as well, which will immediately use the latest code

Ken Huang 2025-01-30T00:44:00.196979Z

Thanks, I’ll try these. My use case of the hook is to generate a chrome extension’s manifest.json from a Clojure map, is it possible not using a hook?

Ken Huang 2025-01-31T08:47:08.706609Z

I use cider to start the repl, and I didn't yet figured out how to bring out the CLJ REPL. But I've workaround-ed the issue by calling load-file in the look following your pointer, thanks!