gpt4 book ai didi

clojure - 如何让 cljsbuild 在 uberjar 编译 clojure 应用程序之前运行?

转载 作者:行者123 更新时间:2023-12-02 04:18:28 27 4
gpt4 key购买 nike

我正在 clojure/clojurescript/reagennt 中制作同构应用程序。由于我依赖于 clojurescript 输出 js 文件进行服务器端渲染,因此我希望在 jar 之前编译该文件。我怎么做?

这是“lein uberjar”的输出,注意 jar 是首先编译的。我的 clj 文件“nash.clj”需要运行已编译的 server-side.js 版本:

Johns-MacBook-Pro:bfa-clojure johnkealy$ lein uberjar

minifying assets...

minifying: resources/public/css/site.min.css
assets: site.css
original size: 88983
compressed size: 73886
gzipped size: 13676
Compiling bfa-clojure.api.auth
Compiling bfa-clojure.api.misc
Compiling bfa-clojure.api.photos
Compiling bfa-clojure.global
Compiling bfa-clojure.handler
Compiling bfa-clojure.nash
Compiling bfa-clojure.pages
Compiling bfa-clojure.server
2015-08-17 14:34:32.964:INFO::main: Logging initialized @21242ms
Compiling ClojureScript.
Compiling "resources/public/javascripts/server-side.js" from ("src/cljs" "src/server-cljs" "src/clj/bfa_clojure/queries" "src/cljs" "src/server-cljs" "src/clj/bfa_clojure/queries")...
Successfully compiled "resources/public/javascripts/server-side.js" in 7.441 seconds.

还有我的project.clj...整个 cljsbuild 的事情目前对我来说还是个谜。

(defproject bfa-clojure "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}

:source-paths ["src/clj" "src/cljs"]

:dependencies [[org.clojure/clojure "1.7.0"]
[ring-server "0.4.0"]
[cljsjs/react "0.13.3-1"]
[reagent "0.5.0"]
[reagent-forms "0.5.4"]
[reagent-utils "0.1.5"]
[ring "1.4.0"]
[cider/cider-nrepl "0.7.0"]
[org.clojure/tools.nrepl "0.2.3"]
[ring/ring-defaults "0.1.5"]
[prone "0.8.2"]
[cheshire "5.3.1"]
[fogus/ring-edn "0.3.0"]
[org.clojure/data.json "0.2.6"]
[com.cemerick/url "0.1.1"]
[org.clojure/core.async "0.1.267.0-0d7780-alpha"]
[clj-http "2.0.0"]
[compojure "1.4.0"]
[cljs-ajax "0.3.13"]
[hiccup "1.0.5"]
[environ "1.0.0"]
[org.clojure/clojurescript "0.0-3308" :scope "provided"]
[mori "0.2.4"]
[secretary "1.2.3"]]

:less {:source-paths ["src/less"]
:target-path "resources/public/css"}

:plugins [[lein-less "1.7.5"]
[lein-environ "1.0.0"]
[lein-asset-minifier "0.2.2"]]

:ring {:handler bfa-clojure.handler/app
:uberwar-name "bfa-clojure.war"}

:min-lein-version "2.5.0"

:uberjar-name "bfa-clojure.jar"

:main bfa-clojure.server

:clean-targets ^{:protect false} [:target-path
[:cljsbuild :builds :app :compiler :output-dir]
[:cljsbuild :builds :app :compiler :output-to]]

:minify-assets
{:assets
{"resources/public/css/site.min.css" "resources/public/css/site.css"}}

:cljsbuild {:builds {:app {:source-paths ["src/cljs" "src/client-cljs" "src/clj/bfa_clojure/queries"]
:compiler {:output-to "resources/public/js/app.js"
:output-dir "resources/public/js/out"
:asset-path "/js/out"
:optimizations :none
:pretty-print true}}}}

:profiles {:dev {:repl-options {:init-ns bfa-clojure.repl
:nrepl-middleware []}

:dependencies [[ring-mock "0.1.5"]
[ring/ring-devel "1.4.0"]
[lein-figwheel "0.3.7"]
[org.clojure/tools.nrepl "0.2.10"]
[pjstadig/humane-test-output "0.7.0"]]

:source-paths ["env/dev/clj"]
:plugins [[lein-figwheel "0.3.7"]
[lein-cljsbuild "1.0.6"]]

:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]

:figwheel {:http-server-root "public"
:server-port 3449
:nrepl-port 7002
:css-dirs ["resources/public/css"]
:ring-handler bfa-clojure.handler/app}

:env {:dev true}

:cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"]
:compiler {:main "bfa-clojure.dev"
:source-map true}}
:server {:id "server-side"
:source-paths ["src/cljs" "src/server-cljs" "src/clj/bfa_clojure/queries"]
:compiler {:output-to "resources/public/javascripts/server-side.js"
:output-dir "resources/public/javascripts/out-server-side"
:preamble ["underscore-min.js"]
:pretty-print false
:warnings true
:optimizations :whitespace}}}}}

:uberjar {:hooks [leiningen.cljsbuild minify-assets.plugin/hooks]
:env {:production true}
:aot :all
:omit-source true
:cljsbuild {:jar true
:main "bfa-clojure.core"
:builds {
:server {:id "server-side"
:source-paths ["src/cljs" "src/server-cljs" "src/clj/bfa_clojure/queries"]
:compiler {:output-to "resources/public/javascripts/server-side.js"
:output-dir "resources/public/javascripts/out-server-side"
:preamble ["underscore-min.js"]
:pretty-print false
:warnings true
:optimizations :whitespace}}

:app
{:source-paths ["env/prod/cljs"]
:externs ["underscore-min.js"]
:compiler
{:optimizations :advanced
:externs ["underscore-min.js"]
:pretty-print false}}}}}})

最佳答案

您必须添加 cljsbuild hooks在您的项目.clj 中:

:hooks [leiningen.cljsbuild]

关于您的 lein uberjar 输出,您说:

notice the jar is compiled first

事实并非如此。我按顺序看到以下任务的输出:- lein minify (或者任何被命名为缩小 css 的任务)- 莱因编译- lein cljsbuild 一次

我们无法从输出中判断 jar 任务是否在这些任务之前或之后运行,但这就是它的工作原理:默认情况下,uberjar 运行 clean -> javac -> 编译 -> jar

该钩子(Hook)使 cljsbuild 在 compile 任务之后运行。这就是为什么您在“编译 ClojureScript”之前看到“编译 bfa-clojure.api.auth...”的原因

关于clojure - 如何让 cljsbuild 在 uberjar 编译 clojure 应用程序之前运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32041225/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com