在运行时在 clojurescript 中添加 class 路径?

Adding class paths in clojurescript at runtime?

是否可以在运行时在 Nodejs 上的 Clojurescript 程序 运行 中添加类路径?

假设您指的是在开发时修改基于节点的 REPL 的类路径,也许 add-lib becomes a thing, then this would be pretty easy to do. Here is an experiment showing using add-lib in a revised 版本的 ClojureScript 动态修改类路径并加载(动态获取的)库:

deps.edn:

{:deps {org.clojure/clojurescript {:git/url "https://github.com/mfikes/clojurescript"
                                   :sha "4fa9edd736d47b8ef5648b61b199e64ef80735bb"}
        org.clojure/tools.deps.alpha {:git/url "https://github.com/clojure/tools.deps.alpha.git"
                                      :sha "d492e97259c013ba401c5238842cd3445839d020"}}}

使用它:

$ clj -m cljs.main -re node
cljs.user=> (require '[cljs.repl :refer [add-lib]])
nil
cljs.user=> (add-lib 'spec-provider {:mvn/version "0.4.14"})
Downloading: spec-provider/spec-provider/0.4.14/spec-provider-0.4.14.pom from https://repo.clojars.org/
Downloading: spec-provider/spec-provider/0.4.14/spec-provider-0.4.14.jar from https://repo.clojars.org/
true
cljs.user=> (require '[spec-provider.provider :as sp])
nil
cljs.user=> (sp/infer-specs
 [{:a 8  :b "foo" :c :k}
  {:a 10 :b "bar" :c "k"}
  {:a 1  :b "baz" :c "k"}]
 :toy/small-map)
((cljs.spec.alpha/def :toy/c (cljs.spec.alpha/or :keyword cljs.core/keyword? :string cljs.core/string?)) (cljs.spec.alpha/def :toy/b cljs.core/string?) (cljs.spec.alpha/def :toy/a cljs.core/integer?) (cljs.spec.alpha/def :toy/small-map (cljs.spec.alpha/keys :req-un [:toy/a :toy/b :toy/c])))
cljs.user=>