【问题标题】:Where is the "Hello world" going to be printed after following shadow-cljs documentation to watch the app?按照 shadow-cljs 文档观看应用程序后,“Hello world”将在哪里打印?
【发布时间】:2022-10-04 16:17:35
【问题描述】:

我正在关注 shadow-cljs快速开始有关项目最小示例的文档。这里是the link

我有这个shadow-cljs.edn 文件:

;; shadow-cljs configuration
{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 :dev-http {8080 "public"}
 :dependencies
 []

 :builds
 {:frontend
  {:target :browser
   :modules {:main {:init-fn acme.frontend.app/init}}
   }}}

/Users/pedro/projects/acme-app/src/main/acme/frontend/app.cljs,我还有:

(ns acme.frontend.app)

(defn init []
  (println "Hello World"))

我可以使用以下命令构建和观看它:

$ npx shadow-cljs watch frontend


shadow-cljs - config: /Users/pedro/projects/acme-app/shadow-cljs.edn
shadow-cljs - HTTP server available at http://localhost:8080
shadow-cljs - server version: 2.20.2 running at http://localhost:9630
shadow-cljs - nREPL server started on port 61214
shadow-cljs - watching build :frontend
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build completed. (127 files, 0 compiled, 0 warnings, 6.97s)

由于init 函数是一个“Hello World”函数,我期待在某个地方看到它。但是,我找不到任何地方“展示”Hello World 来查看它的效果。

“Hello World”应该“出现”在哪里?是不是应该只要可以在 IDE 内的 REPL 中作为程序员调用的函数使用?

“你好世界”是不是打印在终端上(见上面检索到的消息),不显示在localhost:8080 的 UI 上(可能需要在 HTML 中进行调整 - 见下图),并且不出现在浏览器控制台上(可能需要js/console.log)。

这些是在执行npx shadow-cljs node-repl 后调用 REPL 中的函数的失败尝试:

cljs.user=> (acme.frontend.app/init)
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:1:2
 Use of undeclared Var acme.frontend.app/init
--------------------------------------------------------------------------------

cljs.user=> (main.acme.frontend.app/init)
------ WARNING - :undeclared-ns ------------------------------------------------
 Resource: <eval>:1:2
 No such namespace: main.acme.frontend.app, could not locate main/acme/frontend/app.cljs, main/acme/frontend/app.cljc, or JavaScript source providing "main.acme.frontend.app"
--------------------------------------------------------------------------------

这是localhost:8080 上的图片:

【问题讨论】:

    标签: printing clojurescript read-eval-print-loop shadow-cljs


    【解决方案1】:

    如快速入门中所述,您似乎已跳过 public/index.html 的创建。该构建使用:target :browser,因此它旨在加载到浏览器中。 HTML 会做到这一点。加载后,您将在浏览器控制台中看到 println

    对于 REPL,代码总是需要在可以使用之前加载。因此,在运行(x/init) 之前,您需要一个(require '[acme.frontend.app :as x])

    【讨论】:

      猜你喜欢
      • 2020-11-02
      • 2015-05-04
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 2018-03-11
      • 2014-01-10
      相关资源
      最近更新 更多