【问题标题】:Trying to use re-frame-10x (was re-frame-trace) with descjop (electron) project尝试将 re-frame-10x(是 re-frame-trace)与 descjop(电子)项目一起使用
【发布时间】:2018-02-28 17:17:38
【问题描述】:

我正在尝试使用 re-frame 和电子的组合来设置一个项目,我想安装 re-frame-10x,以便我可以轻松地查看 app-db 的某些部分。我之前已经将它与通过谷歌浏览器访问的常规 clojurescript/re-frame 项目一起使用,但尚未使用电子。我很有希望,因为我相信 electron 使用的代码与引擎盖下的 chrome 基本相同。

我按照 re-frame-10x github 页面上的设置说明进行操作,似乎一切正常。但是我无法调出 10x 窗口。

这是我的 project.clj 文件的一部分,特别是 clojurescript 开发版本:

  :cljsbuild
  {:builds
   {:dev-main {:source-paths ["src"]
               :incremental true
               :jar true
               :assert true
               :compiler {:output-to "app/dev/js/cljsbuild-main.js"
                          :externs ["app/dev/js/externs.js"
                                    "node_modules/closurecompiler-externs/path.js"
                                    "node_modules/closurecompiler-externs/process.js"]
                          :warnings true
                          :elide-asserts true
                          :target :nodejs
                          :output-dir "app/dev/js/out_main"
                          :optimizations :simple
                          :pretty-print true
                          :output-wrapper true
                          :closure-defines      {"re_frame.trace.trace_enabled_QMARK_" true}
                          :preloads             [day8.re-frame-10x.preload]
                          :main "anh.core" }}

    :dev-front {:source-paths ["src_front" "src_front_profile/anh_front/dev"]
                :incremental true
                :jar true
                :assert true
                :compiler {:output-to "app/dev/js/front.js"
                           :externs ["app/dev/js/externs_front.js"]
                           :warnings true
                           :elide-asserts true
                           :optimizations :none
                           :output-dir "app/dev/js/out_front"
                           :pretty-print true
                           :output-wrapper true }}

请注意,有 2 个构建。 (figwheel-status) 告诉我它正在监视和重新编译 dev-front。 dev-main 包含指向 re-frame-10x 需要的 main 的指针。

Clojurescript 已升级到最新版本“1.10.64”,一切看起来都很好,在 repl 启动(使用来自 emacs 的插件)或 clojurescript repl 启动时没有错误消息。

仍然没有 re-frame-10x 窗口的迹象。当我在应用程序窗口中按 ctrl-h 时,它应该会出现。

这条线下面是我在路上尝试的东西。可能无关紧要。


回滚 clojure repl 消息,我发现它在 cljs repl 启动期间遇到了 re-frame-10x 的某种问题:

user> Figwheel: Starting server at http://0.0.0.0:3441
Figwheel: Watching build - dev-front
Figwheel: Cleaning build - dev-front
Compiling "app/dev/js/front.js" from ["src_front" "src_front_profile/anh_front/dev"]...
Failed to compile "app/dev/js/front.js" in 10.853 seconds.
----  Could not Analyze  app/dev/js/out_front/day8/re_frame_10x/subs.cljs  ----

  No such namespace: cljs.spec.alpha, could not locate cljs/spec/alpha.cljs, cljs/spec/alpha.cljc, or Closure namespace "cljs.spec.alpha"

----  Analysis Error : Please see app/dev/js/out_front/day8/re_frame_10x/subs.cljs  ----
Launching ClojureScript REPL for build: dev-front

知道这意味着什么吗?我还没有使用 cljs.spec,但编译器似乎正在寻找它。

这是 project.clj 文件的一部分,其中包含 re-frame-10x 要求的修改,特别是相关 cljsbuild 部分的编译器部分中的闭包定义、预加载和到 main 的链接:

:dev-front {:source-paths ["src_front" "src_front_profile/anh_front/dev"]
            :incremental true
            :jar true
            :assert true
            :compiler {:output-to "app/dev/js/front.js"
                       :externs ["app/dev/js/externs_front.js"]
                       :warnings true
                       :elide-asserts true

                       :optimizations :none
                       :output-dir "app/dev/js/out_front"

                       :pretty-print true
                       :output-wrapper true
                       :closure-defines      {"re_frame.trace.trace_enabled_QMARK_" true}
                       :preloads             [day8.re-frame-10x.preload]
                       :main "anh.core"
                       }}

更新:

这有助于: No such namespace: clojure.spec.alpha in clojurescript project setup 根据建议,我将 clojurescript 升级到具有所需规范内容的最新版本,并且当启动 cljs repl 时,repl 显示不同的错误:

Failed to load resource: net::ERR_FILE_NOT_FOUND
cljs_deps.js Failed to load resource: net::ERR_FILE_NOT_FOUND
base.js:677 goog.require could not find: day8.re_frame_10x.preload
goog.logToConsole_ @ base.js:677
base.js:711 Uncaught Error: goog.require could not find: day8.re_frame_10x.preload
    at Object.goog.require (base.js:711)
    at index.html:11
base.js:677 goog.require could not find: anh.core
goog.logToConsole_ @ base.js:677
base.js:711 Uncaught Error: goog.require could not find: anh.core
    at Object.goog.require (base.js:711)
    at index.html:11
base.js:677 goog.require could not find: anh_front.init
goog.logToConsole_ @ base.js:677
base.js:711 Uncaught Error: goog.require could not find: anh_front.init
    at Object.goog.require (base.js:711)
    at index.html:12

这只是未找到的主要功能。 project.clj 文件指定了 2 个开发版本,dev-front 和 dev-main。我在错误的部分中有 clojurescript 编译器选项。将它们移动到正确的部分可以消除错误,但是当我按 ctrl-h 时仍然不会出现 re-frame-10x 窗口。

【问题讨论】:

    标签: electron clojurescript re-frame


    【解决方案1】:

    解决此问题的关键是将其放入正确的构建中。 Descjop 有 2 个开发版本,一个用于应用程序本身(dev-main),一个用于窗口(dev-front)。 Dev-main 可以并且可能应该被单独留下。更改需要在 dev-front 构建中进行。

    步骤 1

    将 dev-front 构建转换为 :optimizations none。这是 re-frame-10x 的要求之一。为此,需要在 :dev-front :compiler 部分下的 profile.clj 的 cljsbuild 部分中添加以下内容:

    :main "setup-front.init"
    :asset-path "js/out_front"
    

    然后可以将 html 文件简化为“setup-front.init”将为您加载必要的内容。像这样的:

    <body>
    
      <div id="app">
        <p>Minimum app does not work.</p>
      </div>
    
      <script type="text/javascript" src="js/front.js" charset="utf-8"></script>
    
    </body>
    

    第二步

    升级! Descjop 默认使用旧版本的 clojurescript,它不提供 re-frame-10x 使用的某些功能。 org.clojure/clojurescript "1.10.64" 对我有用。

    之后可以关注re-frame-10x instructions,它应该可以正常工作。简而言之,将以下内容添加到您放置 :main 语句的位置旁边的 cljsbuild 部分

    :closure-defines      {"re_frame.trace.trace_enabled_QMARK_" true}
    :preloads             [day8.re-frame-10x.preload]
    

    并将其添加到依赖项中。可能最好进入 :profiles :dev 部分。不过,请查看说明或 clojars 以获取最新版本:

    [day8.re-frame/re-frame-10x "0.2.1-SNAPSHOT"]
    

    使用这些更改的非常基本的 hello-world 的源代码可在 github 上获得

    感谢 Mike Callahan 提供此解决方案的要点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      • 2018-02-20
      • 2022-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多