本文介绍了如何正确设置shadow-cljs进行热重装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使shadow-cljs热重装正常工作,但我一直无法这样做,我已经尝试了project.clj文件中的多个设置,但没有一个起作用.这就是我的project.clj的样子:

I've been trying to get shadow-cljs hot reload to work but I haven't been able to, I've tried multiple settings in my project.clj file but none have worked. This is what my project.clj looks like:

:shadow-cljs {:nrepl {:port 8777}

                :builds {:app {:target :browser
                               :output-dir "resources/public/js/compiled"
                               :asset-path "/js/compiled"
                               :modules {:app {:init-fn my-app.core/init
                                               :preloads [devtools.preload]}}

                               :devtools {:http-root "resources/public"
                                          :http-port 8080
                                          :http-handler my-app.handler/dev-handler
                                          }}}}

:aliases {"watch"        ["with-profile" "dev" "do"
                          ["shadow" "watch" "app"]]}

:profiles
  {:dev
   {:dependencies [[binaryage/devtools "1.0.2"]]
    :source-paths ["dev"]} ;; <- this is the default from the template pointing to "dev", I've tried chaning it multiple times.
  }

当我运行 lein watch 时,我了解到它只是在运行 shadow-cljs watch app ,它应运行我的"app"应用程序.建造.这就是我的开发处理程序的外观(在:http-handler 中引用):

When I run lein watch I understand that it's just running shadow-cljs watch app which should run my "app" build. This is what my dev-handler looks like (referenced in :http-handler):

(def dev-handler (-> api-routes
                     wrap-params
                     wrap-json-response
                     wrap-keyword-params
                     wrap-json-params
                     wrap-multipart-params
                     wrap-reload
                     (wrap-resource "public")
                     (utils/cors-wrapper utils/cors-policy)
                     (utils/wrap-content-type-security)
                     (wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))))

我尝试将我的:dev配置文件中的源路径更改为 ["src"] ,甚至尝试包括所有内部文件夹,如["src/clj""src/cljs""src/cljc"] 失败.我什至尝试使用 lein new re-frame 从头开始创建一个新应用,并且不进行任何更改并运行lein watch,代码编译,并且一切似乎都很好,但是每当我在cljs文件中更改某些内容时((例如.cljs)),什么都没有重新渲染/重新加载,我去了localhost:9630,它为您提供了一个shadow-cljs仪表板,其中列出了您的构建并单击了"force compile"(强制编译).按钮,并在我的应用程序页面中看到clojurescript动画,但没有再次重新渲染/重新加载.我注意到,shadow-cljs完成编译后,已编译了0个文件,是否从其他位置获取了source-paths配置?这是我尝试对其进行测试时的外观:

I've tried changing the source-paths in my :dev profile to ["src"] and even tried including all inner folders as in ["src/clj" "src/cljs" "src/cljc"] with no success. I've even tried creating a new app from scratch with lein new re-frame making no changes whatsoever and running lein watch, code compiles and everything seems fine but whenever I change something in a cljs file (views.cljs for example) nothing is re-rendered/reloaded, I've gone to localhost:9630 which gives you a shadow-cljs dashboard listing your builds and clicked on the "force compile" button and see a clojurescript animation in my app's page but no re-rendering/reloading again. I notice that when shadow-cljs finishes compiling, there are 0 files compiled, is it getting the source-paths config from somewhere else? This is what it looks like when I'm trying to test it out:

也许值得一提,我正在MobaXterm中使用xfce终端和来自WSL2的emacs运行ubuntu,这可能与代码/应用程序不热重装有关吗?

Maybe it's worth saying that I'm running ubuntu with xfce terminal and emacs from WSL2 within MobaXterm, could it have something to do with the code/app not hot reloading?

推荐答案

一切似乎都按预期顺利进行.可能唯一缺少的是生命周期回调,以触发页面的实际重新渲染.

Everything seems to be running smoothly and as intended. It might be that the only thing you are missing is a lifecycle callback to trigger the actual re-render of your page.

请参见 https://shadow-cljs.github.io/docs/UsersGuide.html#_hot_code_reload

在大多数重新框架/试剂应用程序中,该应用程序将调用 reagent.dom/render (如果您使用的是旧版本,则调用 reagent.core )

In most re-frame/reagent apps that would be the function that calls reagent.dom/render (or reagent.core in case you are on old version).

我还写了更多有关这一切如何工作的内容此处.

I also wrote more about how this all works here.

shadow-cljs 会查看JVM类路径,但是它是在启动时构建的.您似乎使用的是 lein ,所以这里只有 project.clj 很重要,并且通过添加所有:source-paths :resource-paths 等.因此,如果您有:source-paths ["src/clj""src/cljs""src/cljc"] 就足够了,只要假定您正在使用的源文件实际上在这些目录中即可.

shadow-cljs looks at the JVM classpath however that is constructed on startup. You appear to be using lein so only project.clj will matter here and the classpath is constructed by adding all :source-paths, :resource-paths and so on. So if you have :source-paths ["src/clj" "src/cljs" "src/cljc"] that will be enough for it to be picked up, assuming of course the source files you are working with are actually in those dirs.

否则无法评论您的设置.我在WSL2上使用得很好,但是如果在容器(例如docker)中运行,则存在一些已知问题,因此在此我不排除某些时髦的东西会阻止 shadow-cljs 真正地监视"它们.文件.

Can't comment on your setup otherwise. I used it fine with WSL2 but there are known issues if running inside containers (eg. docker) so I wouldn't rule out something being funky here that prevents shadow-cljs from actually "watching" the files.

这篇关于如何正确设置shadow-cljs进行热重装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 08:59