如何让devcards使用shadow-cljs

时间:2018-06-18 14:21:57

标签: fulcro

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

暗影发出此消息:

  

shadow-cljs - 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}}
              }

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

1 个答案:

答案 0 :(得分:1)

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

lein new fulcro app shadow-cljs

此处app是您选择的任何名称,shadow-cljs是一个选项。在研究了生成的应用程序之后,我意识到命名空间cards.card-ui不应该只是一个需求列表,而是需要这些行:

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

(defn refresh []
  (println "In cards.card-ui that starts the ui"))

: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}
              }

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

<body>
    <div id="app"></div>
    <script src="js/cards/main.js"></script>
</body>

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

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