我正在使用Leiningen 2.5.2(Java 1.8.0_45-内部Open JDK 64位)和试剂模板(即lein new reagent foo)。

可以按预期在lein figwheel上运行。

接下来,我要做的第一件事是将“视图”功能分解为单独的文件,并将它们添加到应用程序名称空间:

core.cljs片段:

;; -------------------------
;; Views

(:require home-page)


home-page.cljs(整个文件):

(ns foo.core)

(defn home-page []
  [:div [:h2 "Welcome to foo"]
   [:div [:a {:href "#/about"} "go to about page"]]])


当我在浏览器(铬或Firefox)中查看应用程序时,它卡在“ ClojureScript尚未编译!”中。尽管似乎在终端中编译成功。如果在figwheel REPL中输入命令,当它在浏览器中运行时,我会看到绿色的Clojure徽标,因此我知道它已连接。

几个月前,我在试剂应用程序中进行了这项工作-发生了什么事?我应该如何分隔视图代码? (单个文件无法管理;这是很多麻烦。)

最佳答案

如果在core.cljs中确实只有(:require home-page)行,那应该是罪魁祸首。冒号:require仅在带有ns的名称空间声明内有效。另外,您在错误的文件(home-page.cljs,而不是core.cljs)中声明了核心名称空间。请参阅this article on namespaces in Clojure以获取详细说明。

您将在core.cljs中需要以下内容:

(ns foo.core
  (:require [foo.home-page :as hp :refer [home-page]]))
.... more core.cljs code ...


然后只需在home-page.cljs中:

(ns foo.home-page
  (:require ....reagent namespaces as needed ....

(defn home-page [] ....

关于java - Figwheel为什么不将编译的应用程序传递给浏览器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32705441/

10-12 06:18