首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"Hello“在看完这个应用程序后,会被打印在哪里呢?

"Hello“在看完这个应用程序后,会被打印在哪里呢?
EN

Stack Overflow用户
提问于 2022-10-03 21:53:51
回答 1查看 83关注 0票数 0

我正在跟踪一个项目的最小示例的影子-cljs快速启动文档。这是链接

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

代码语言:javascript
复制
;; 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中,我还拥有:

代码语言:javascript
复制
(ns acme.frontend.app)

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

我可以使用命令构建并查看它:

代码语言:javascript
复制
$ 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“函数,所以我希望在某个地方看到它。但是,我找不到任何地方“展示”“你好世界”来看它的效果。

“你好世界”应该出现在哪里?是否假定中只有才能作为程序员调用的函数在中可用?

"hello world“没有打印在终端上(见上面检索到的消息),也没有显示在localhost:8080上的UI上(这可能需要在HTML中进行调整--参见下面的图),也不会出现在浏览器控制台上(可能需要js/console.log)。

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

代码语言:javascript
复制
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上的图像

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-04 04:48:03

您似乎跳过了“快速启动”中提到的public/index.html的创建。构建使用的是:target :browser,因此它意味着要在浏览器中加载。HTML会做到这一点。加载时,您将在浏览器控制台中看到println

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73941197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档