如何让开发卡与 shadow-cljs 一起工作

Chr*_*phy 4 fulcro

我的开发卡曾经与 Figwheel 一起使用。但是我无法让它们用 shadow-cljs 显示。

阴影发出此消息:

shadow-cljs - 用于 :cards 的 HTTP 服务器,可在http://localhost:3450

命名空间cards.card-ui只是一系列的需求。

我有一条println消息cards.card-ui正在显示。

shadow-cljs.edn我有两个:builds. 这是第二个:

      :cards {:target           :browser
              :output-dir       "resources/public/js/cards"
              :asset-path       "js/cards"
              :modules          {:main {:entries [cards.card-ui]}}
              :compiler-options {:static-fns false}
              :devtools         {:http-root          "resources/public"
                                 :http-resource-root "resources/public"
                                 :http-port          3450
                                 :http-handler       shadow.http.push-state/handle
                                 :push-state/index   "cards.html"
                                 :preloads           [devtools.preload
                                                      default-db-format.preload]}
              :dev              {:compiler-options {:devcards true}}
              }
Run Code Online (Sandbox Code Playgroud)

cards.html有一个body标签,它有一个id为“app”的div标签。我将浏览器带到http://localhost:3450/cards.html并得到一个空白页面。我最好的理论是cards.card-ui命名空间没有安装在app.

Chr*_*phy 5

目前,获得使用 shadow-cljs 而不是 Figwheel 的示例 Fulcro 应用程序的唯一方法是通过 lein 模板。所以在命令提示符下:

lein new fulcro app shadow-cljs
Run Code Online (Sandbox Code Playgroud)

app是您选择的任何名称,并且shadow-cljs是一个选项。在研究了生成的应用程序后,我意识到命名空间cards.card-ui不应该只是一个需求列表,还需要有以下几行:

(devcards.core/start-devcard-ui!)

(defn refresh []
  (println "In cards.card-ui that starts the ui"))
Run Code Online (Sandbox Code Playgroud)

:cards在建shadow-cljs.edn变得简单一点:

      :cards {:target           :browser
              :output-dir       "resources/public/js/cards"
              :asset-path       "js/cards"
              :compiler-options {:devcards true}
              :modules          {:main
                                 {:entries [cards.card-ui]}}
              :devtools         {:after-load cards.card-ui/refresh
                                 :http-root "resources/public"
                                 :http-port 3450}
              }
Run Code Online (Sandbox Code Playgroud)

我做错的另一件事是 HTML ( cards.html)。这里只是body标记的标签:

<body>
    <div id="app"></div>
    <script src="js/cards/main.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)

Devcards 站点的一些导入指针:https : //github.com/bhauman/devcards#usage-without-figwheel

lein 模板项目:https : //github.com/fulcrologic/fulcro-lein-template