我正在玩Figwheel并编写一个简单的单页应用程序,不需要任何服务器端智能.
原则上,这个程序.可以放在任何静态Web服务器上.
但是我该如何实际部署呢?看起来我的Figwheel开发环境中的main.js正在设置图形连接.
我实际需要将什么js和html文件放在我的静态服务器上?Figwheel是否创建了它们,还是我需要创建一个新的main.js和index.html?我在哪里可以找到例子?
该文档非常适合如何开始使用Figwheel,但令人惊讶的是对完成开发后的操作保持沉默.
我有一个宏从资源中啜饮markdown文件.它提供了一种提供一些内容的便捷方式.但是当我编辑markdown文件时,Figwheel无法知道它需要重新评估宏.
将markdown放在cljs文件中的字符串中是不可取的,因为具有换行符的字符串会被大多数Clojure编辑器缩进,这会导致markdown不正确(前导空格在markdown中有意义).
有没有办法在降价文件发生变化时检测/刷新?还是更好的解决方案?
以下是我尝试做的基本示例:https: //github.com/timothypratley/figwheel-watch-markdown-example
lein figwheel和lein cljsbuild auto有什么区别,因为我相信它们都可以用来编译clojurescript。
另外,使用一个比另一个有好处吗?
注意:我是一个一般经验丰富的程序员,使用 clojure,但从未做过认真的 web 开发。
我使用 Chestnut 设置了一个基本的 ClojureScript 项目,并很好地完成了“Hello World”步骤。但是,我也很想与我的后端交谈。为此,我将试剂代码重新定义为
(defn greeting []
[:input {:type "button"
:value (:text @app-state)
:on-click #(http/get {})}])
Run Code Online (Sandbox Code Playgroud)
单击时会收到 404 响应。所以至少我在和某人说话。我还可以在 server.log 文件中看到我的获取请求的证据。然而,在这一点上,我正在努力解决一些概念上的问题。
首先,http/get 是在 clj-http.client 中定义的一个函数,它不是 Chestnut 设置的一部分。如果我必须去寻找图书馆来发送像 get-request 这样基本的东西,感觉就像我已经偏离了轨道。
其次,用户命名空间的文件具有以下由 Chestnut 预定义的行:
(def http-handler
(wrap-reload #'mypage.server/http-handler))
(defn run []
(figwheel/start-figwheel!))
Run Code Online (Sandbox Code Playgroud)
我看不到任何使用过 http 处理程序的地方。所以我不明白这个定义到底是做什么的。
也是我理解 Figwheel 的方式,当我调用“run”时,它会启动一个新的 Web 服务器,然后 a) 提供 index.html 和 b) 通过某个 TCP 端口连接到我的浏览器并开始通过该连接抽取新的 JavaScript . 第二部分对我来说非常具有推测性。如果这真的发生了,我的下一个问题是 Figwheel 是否还需要位于该连接的另一端,或者浏览器是否具有一些允许从外部重新加载代码的通用 API。
最后,我可以说 mypage/server.clj 文件(如下)中定义的环路由和 http-handler 以某种方式被调用,因为修改这些更改了 get-request 中的错误,但是这对我来说完全是个谜这有效。根据我的理解,我从浏览器发送的 get-request 被发送到 Figwheel-server,即站点的来源。我没有理由相信 Figwheel 对我在服务器文件中定义的 …
我的project.clj有,
:cljsbuild {:builds
{:app
{:source-paths ["src/cljs" "src/cljc"]
:compiler {:output-to "target/cljsbuild/public/js/app.js"
:output-dir "target/cljsbuild/public/js/out"
:main "my.core"
:asset-path "/js/out"
:optimizations :none
:source-map true
:pretty-print true}}}}
Run Code Online (Sandbox Code Playgroud)
我包括app.js在我的list.html, 使用Selmer中,就像这样,
{% block page-scripts %}
{% script "/js/app.js" %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
在我的最后list.cljs,我有
(r/render [list] (.getElementById js/document "content"))
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。
现在,我想要另一个页面,比如说detail.cljs,我也想以类似的方式呈现,
(r/render [detail] (.getElementById js/document "content"))
Run Code Online (Sandbox Code Playgroud)
问题是,我只有一个app.js,并将其包含detail.html在其中也会呈现列表内容。顺便说一句,我想要一个list页面的 url,另一个detail.
问题:
我该怎么办?
我刚刚开始尝试使用以下模板制作一个简单的 cljs 应用程序:
lein new figwheel someproject -- --reagent
我希望在 cider 中使用 REPL 进行 cljs 开发,就像我通常在普通 clj 项目中使用的方式一样,所以我做了一些研究并最终得到了这里:
https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl
我通读了说明,并验证了所有正确的依赖项都在 project.clj 中(无需更改任何内容,看起来模板添加了我需要的所有内容)。上面链接中的最后一步表明我需要将以下代码添加到我的 emacs 配置中:
(require 'cider)
(setq cider-cljs-lein-repl
"(do (require 'figwheel-sidecar.repl-api)
(figwheel-sidecar.repl-api/start-figwheel!)
(figwheel-sidecar.repl-api/cljs-repl))")
Run Code Online (Sandbox Code Playgroud)
现在 - 我是一个 emacs 新手,所以我使用的设置仍然是我第一次从“ Clojure for the Brave and True ”中学到的:
https://github.com/flyingmachine/emacs-for-clojure
我试图首先将上面的代码片段放入 中~/.emacs.d/init.el,但是每当我尝试时M-x cider-jack-in ...,都没有cider-jack-in-clojurescript选择。我还尝试将代码片段放在 中~/.emacs.d/customizations/setup-clojure.el,这看起来更合乎逻辑,但结果相同。
我真的很想能够启动并运行这个 REPL,所以任何帮助将不胜感激。
我想在我的ClojureScript构建中使用figwheel.
它lein cljsbuild auto已经合作,但我必须把它:optimisations :whitespace.
否则我在浏览器中收到一条消息:
Uncaught ReferenceError: goog is not defined
Run Code Online (Sandbox Code Playgroud)
然而,figwheel需要:optimisations :none运行.这是我的leiningen文件的一部分:
:cljsbuild {
:builds
[{:id "dev"
:source-paths ["src/cljs"]
:figwheel { :websocket-host "localhost"
;;:on-jsload "example.core/fig-reload"
:autoload true
:heads-up-display true
:load-warninged-code true
;;:url-rewriter "example.core/fig-url-rewrite"
}
:compiler {;; :main
:output-to "resources/public/js/gdb/gdb.js"
:output-dir "resources/public/js/gdb/cljsbuild-dev"
;;:asset-path "js/out"
:optimizations :none
:source-map "resources/public/js/gdb/gdb.js.map"
:pretty-print true}}]}
Run Code Online (Sandbox Code Playgroud)
我缺少什么来获取缺少的依赖项?
我有更新DOM的代码.new-recipe!调用API来获取新的配方字符串.update-recipe-state接下来在屏幕中更新此状态.最后我们打电话给update-transition-buttons.
(defn- add-listener-to-recipe-button! []
"Listens to go button, creates a new recipe and displays it"
(create-click-event-listener! (dommy/sel1 :#button-start)
#(go (new-recipe!)
(<! (timeout 2000))
(update-recipe-state!)
(<! (timeout 2000))
(update-transition-buttons! "onboarding"))))
;; define your app data so that it doesn't get over-written on reload
(defonce world
(add-listener-to-recipe-button!))
Run Code Online (Sandbox Code Playgroud)
在update-transition-buttons有步骤(利用超时代码之间的一些延迟在这里),如下所示:
(defn- update-transition-buttons! [recipe-name]
"Updates the buttons with the transition names"
(go
;; Split response in list of actions by splitting on the comma
(let …Run Code Online (Sandbox Code Playgroud) 我正在观看 Eric Normand 的前端课程/教程。\n课程是付费私人服务。
\n但是,他正在使用 GitHub 上的公共存储库,this\none。
\n克隆并执行后lein fig-dev,该项目似乎已成功构建:
2022-08-25 13:46:47.988:INFO::main: Logging initialized @3006ms to org.eclipse.jetty.util.log.StdErrLog\n[Figwheel] Validating figwheel-main.edn\n[Figwheel] figwheel-main.edn is valid \\(\xe3\x83\x84)/\n[Figwheel] Compiling build dev to "resources/public/js/compiled/app.js"\n[Figwheel] Successfully compiled build dev to "resources/public/js/compiled/app.js" in 1.33 seconds.\n[Figwheel] Watching paths: ("src") to compile build - dev\n[Figwheel:SEVERE] /private/var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/jna1153974339277798676.tmp: dlopen(/private/var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/jna1153974339277798676.tmp, 0x0001): tried: \'/private/var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/jna1153974339277798676.tmp\' (fat file, but missing compatible architecture (have (unknown,i386,x86_64), need (arm64e)))\n[Figwheel] Starting Server at http://localhost:3449\n[Figwheel] Starting REPL\nPrompt will show when REPL connects to evaluation …Run Code Online (Sandbox Code Playgroud)