【问题标题】:Why doesn't figwheel pass the compiled app to the browser?为什么 figwheel 不将编译后的应用程序传递给浏览器?
【发布时间】:2015-12-18 18:09:17
【问题描述】:

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

lein figwheel 可以正常运行。

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

core.cljs sn-p:

;; -------------------------
;; 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"]]])

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

几个月前我在一个试剂应用程序中使用了这个——发生了什么?我应该如何应该分离我的视图代码? (单个文件是无法管理的;这是很多小问题。)

【问题讨论】:

    标签: java clojure leiningen clojurescript reagent


    【解决方案1】:

    如果你在 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 [] ....
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多