[英]Why doesn't figwheel pass the compiled app to the browser?
I'm using Leiningen 2.5.2 (Java 1.8.0_45-internal Open JDK 64-bit), and the reagent-template (ie lein new reagent foo
). 我正在使用Leiningen 2.5.2(Java 1.8.0_45-内部Open JDK 64位)和试剂模板(即lein new reagent foo
)。
This runs okay with lein figwheel
as expected. 与lein figwheel
一起运行可以正常进行。
Next, the first thing I do is break out the "Views" functions into separate files and add them to the app namespace: 接下来,我要做的第一件事是将“视图”功能分解为单独的文件,并将它们添加到应用程序名称空间:
;; -------------------------
;; Views
(:require home-page)
(ns foo.core)
(defn home-page []
[:div [:h2 "Welcome to foo"]
[:div [:a {:href "#/about"} "go to about page"]]])
When I go to view the app in the browser (chromium or firefox), it gets stuck at "ClojureScript has not been compiled!" 当我在浏览器(铬或Firefox)中查看应用程序时,它卡在“ ClojureScript尚未编译!”中。 despite seemingly compiling successfully in the terminal. 尽管似乎在终端中编译成功。 If I enter commands in the figwheel REPL, I see the green Clojure logo when it is working in the browser, so I know it's connected. 如果我在figwheel REPL中输入命令,当它在浏览器中运行时,我会看到绿色的Clojure徽标,因此我知道它已连接。
I had this working in a reagent app some months ago--what happened? 几个月前,我曾在试剂应用程序中进行过这项工作-发生了什么事? How should I separate my view code? 我应该如何分隔视图代码? (A single file is unmanageable; that's a lot of Hiccup.) (单个文件无法管理;这是很多麻烦。)
If you really have only the line (:require home-page)
in core.cljs, this should be the culprit. 如果您实际上在core.cljs中只有一行(:require home-page)
,那应该是罪魁祸首。 The colon notation :require
is only valid inside a namespace declaration with ns
. 冒号:require
仅在带有ns
的名称空间声明内有效。 Also, you declare the core namespace in the wrong file (home-page.cljs, not core.cljs). 另外,您在错误的文件(home-page.cljs,而不是core.cljs)中声明了核心名称空间。 Take a look at this article on namespaces in Clojure for a thorough explanation. 请参阅这篇有关Clojure中的名称空间的文章,以获取详尽的解释。
You will want the following in core.cljs: 您将在core.cljs中需要以下内容:
(ns foo.core
(:require [foo.home-page :as hp :refer [home-page]]))
.... more core.cljs code ...
and then simply in home-page.cljs: 然后只需在home-page.cljs中:
(ns foo.home-page
(:require ....reagent namespaces as needed ....
(defn home-page [] ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.