按照shadow-cljs文档观看应用程序后,“Hello world”将在哪里打印?

问题描述 投票:0回答:1

我正在关注 Shadow-cljs Quick Start 有关项目最小示例的文档。这是链接

我有这个

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
函数是一个“Hellow World”函数,我希望在某个地方看到它。但是,我找不到任何地方“显示”Hello World 来看看它是否成功。

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

“hello world”not打印在终端上(参见上面检索到的消息),不显示在

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个回答
2
投票

您似乎跳过了

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

对于 REPL,在使用 if 之前始终需要加载代码。因此,在运行

(require '[acme.frontend.app :as x])
之前,您需要一个
(x/init)

© www.soinside.com 2019 - 2024. All rights reserved.