【问题标题】:How can I make figwheel start with a custom initial namespace?如何使 figwheel 以自定义初始命名空间开始?
【发布时间】:2016-03-30 11:00:37
【问题描述】:

我的 clojurescript 代码的 project.clj 指定 :repl-options {:init-ns my-project.core},我通过 start-figwheel! 启动 figwheel。在无花果documentation 它说

;; you can also just call (ra/start-figwheel!)
;; and figwheel will do its best to get your config from the
;; project.clj or a figwheel.edn file`

但是当 figwheel 启动时,它会将我放入 cljs.user 命名空间。我怎样才能让 figwheel 选择这个选项?

我的 figwheel.clj 如下所示:

(require '[figwheel-sidecar.repl :as r]
         '[figwheel-sidecar.repl-api :as ra])

(ra/start-figwheel!
  {:figwheel-options {}
   :build-ids ["dev"]
   :all-builds
   [{:id "dev"
     :figwheel {:devcards true}
     :source-paths ["src"]
     :compiler {:main 'my-project.core
                :asset-path "js"
                :output-to "resources/public/js/main.js"
                :output-dir "resources/public/js"
                :verbose true}}]})

(ra/cljs-repl)

我基本上是在 Google 群组中询问this question

【问题讨论】:

  • 当您从外部 REPL 客户端使用 lein repl -c 或在执行 (ra/start-figwheel) 的同一 REPL 中连接时,命名空间是否未更改?
  • 我添加了我的 figwheel.clj。我正在连接我的浏览器,然后在我启动脚本的终端中显示 repl 提示符(带有cljs.user)。我试过lein repl :connect 3449,但这只是挂了。
  • 我认为:repl-options 仅用于 lein 的 repl 任务,而不是 figwheel 本身。你如何使用你的figwheel.clj?将其作为脚本执行还是在 REPL 会话中加载?
  • 我通过一个包含rlwrap lein run -m clojure.main script/figwheel.clj 行的bash 脚本在命令行上执行了figwheel.clj。你是对的,:repl-options 很可能根本没有被选中。很多时候我觉得我没有完全了解工具,哪个流程调用其他流程。我想我需要画一些图表。

标签: clojurescript figwheel


【解决方案1】:

start-figwheel! 仅启动无花果逻辑。关于您的发现:

;; you can also just call (ra/start-figwheel!)
;; and figwheel will do its best to get your config from the
;; project.clj or a figwheel.edn file`

它确实找到了它的配置但是it's only :figwheel submap of project.clj

:repl-options 被 REPL 在启动时使用。 figwheel-sidecar.repl-api/cljs-repl 似乎不允许指定 REPL 选项,并且它不会从 project.clj 中读取它们。

您可以尝试从 lein repl 开始,其中 project.clj 的 :repl-options 使用 :init 选项提供您要执行的代码而不是独立脚本。

【讨论】:

  • 感谢 Piotrek 挖掘了相关的 figwheel 代码!总而言之,我没有从 figwheel 的 repl API 启动 repl,而是使用 lein 的 repl 功能,并将 figwheel 代码加载到其中(通过 project.clj 的 :init 选项)。
  • 我将对start-figwheel!(和require 代码)的调用放入do 下的:init thunk 中,但它没有工作,因为它找不到源文件。我也觉得:init 不是为此而生的。因此,您的答案是正确的,因为 figwheel 没有从 project.clj 获取 :repl-options 的功能,但我们似乎无能为力。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
相关资源
最近更新 更多