在命令行
您可以通过命令行在某种程度上实现这一点,而无需创建build.boot
file:
在 C:\dev\my_project 中:
boot -r src repl -n my-project.utils
-
boot -r src
: 开始启动src
在“资源路径”上,这是可在 JVM 中访问的目录集。
-
repl -n my-project.utils
启动 REPL,需要您的命名空间,然后输入它。
当 REPL 运行时以及编辑后C:\dev\my_project\src\my_project\utils.clj
,您可以像这样在 REPL 中重新加载它:
my-project.utils=> (require 'my-project.utils :reload)
nil
minimal build.boot
或者,您可以创建文件C:\dev\my_project\build.boot
包含这些内容:
(set-env! :resource-paths #{"src"})
(deftask dev
"Run a development REPL"
[]
(repl :init-ns 'my-project.utils))
然后,在C:\dev\my_project
:
boot dev
这也会在你的命名空间中启动 REPL,但需要更少的命令行配置,因为我们已经在build.boot
, which boot
会自动评估。
注意:在 Clojure REPL 中,无论使用哪种构建工具,您都可以使用以下命令来请求任何命名空间(只要它位于 JVM 的类路径上):require
函数并输入in-ns
功能。
自动重新加载的 build.boot
最后,可以结合 Boot 的功能来实现围绕自动重新加载代码的开发工作流程。
In C:\dev\my_project\build.boot
:
(set-env! :resource-paths #{"src"})
(require '[boot.core :as core]
'[boot.pod :as pod])
(deftask load-ns
"Loads the my-project.utils namespace in a fresh pod."
[]
(let [pods (pod/pod-pool (core/get-env))]
(core/with-pre-wrap [fileset]
(pod/with-eval-in (pods :refresh)
;; We require indirectly here so that errors from my-project.utils have
;; proper line and column information.
(require 'my-project.load-impl))
fileset)))
(deftask dev
"Watches source code and loads my-project/utils every time code changes."
[]
(comp (watch)
(load-ns)))
In C:\dev\my_project\src\my_project\load_impl.clj
:
(ns my-project.load-impl)
(require 'my-project.utils)
In C:\dev\my_project\src\my_project\utils.clj
:
(ns my-project.utils
(:require
[clojure.string :as s]))
(defn my-range [start end]
(take (- end start) (iterate inc start)))
(println "In the code!")
(println "(my-range 0 10) = " (my-range 10 20))
返回命令提示符,键入boot dev
。你应该看到一些println
输出,每次编辑和保存文件时,您都应该再次看到它,反映您所做的任何更改。