clojure:devcards:分离出主应用

时间:2016-11-18 05:47:28

标签: clojure

情况

我正在使用clojure + figwheel + devcards。 https://www.youtube.com/watch?v=G7Z_g2fnEDg

除了以下问题外,一切都很棒:

  • 我可以对我的应用的UI组件进行原型设计。但是,我不希望我的完整应用程序在卡片内。

    特别是,我想要以下内容:

localhost:8000 / cards.html< - 显示我的所有命名空间+ devcards localhost:8000 / app.html< - 不要向我展示任何密码;不要给我看一下devcards的目录;只需运行我的应用程序

问题:

如何进行此设置?几乎所有我读过的内容都是关于如何使用devcards 而不是如何设置单独的devcards vs main app的区别。

谢谢!

2 个答案:

答案 0 :(得分:4)

这几乎是devcards模板的默认设置(例如lein new devcards my-app)。

project.clj中有多个版本。一个用于devcards(注意不同的路径和figwheel配置)。 dev几乎是默认值。

(This code is from the template)

 ; ...
 :builds [{:id "devcards"
           :source-paths ["src"]
           :figwheel { :devcards true  ;; <- note this
                      ;; :open-urls will pop open your application
                      ;; in the default browser once Figwheel has
                      ;; started and complied your application.
                      ;; Comment this out once it no longer serves you.
                      :open-urls ["http://localhost:3449/cards.html"]}
           :compiler { :main       "xxx.core"
                      :asset-path "js/compiled/devcards_out"
                      :output-to  "resources/public/js/compiled/xxx_devcards.js"
                      :output-dir "resources/public/js/compiled/devcards_out"
                      :source-map-timestamp true }}
          {:id "dev"
           :source-paths ["src"]
           :figwheel true
           :compiler {:main       "xxx.core"
                      :asset-path "js/compiled/out"
                      :output-to  "resources/public/js/compiled/xxx.js"
                      :output-dir "resources/public/js/compiled/out"
                      :source-map-timestamp true }}
           ;...

现在您需要两个不同的HTML文件。您已经使用的一个(cards.html)和app.html(或模板正在使用的内容:index.html)。他们加载:

<script src="/js/compiled/xxx_devcards.js" type="text/javascript"></script>

另一个:

<script src="/js/compiled/xxx.js" type="text/javascript"></script>

请注意,这些是:output-to中的两个。

使用lein figwheel dev devcards运行此设置。在浏览器中打开索引和卡片。享受。

在实践中,将它分开一点可能更好。您可以通过为:main使用不同的ns来执行此操作,也可以使用多个:source-paths

答案 1 :(得分:3)

我如何只用一个版本来解决这个问题:

1)在HTML中创建一个全局变量,指示是否应加载devcards:

@Transactional("transactionManager2")

2)在您的初始ClojureScript命名空间中检查此变量:

<script type="text/javascript">
  var showDevcards = true; // or false
</script>