簡體   English   中英

為Compojure應用程序自動構建Clojurescript文件

[英]Auto building Clojurescript files for Compojure app

我有一個Web應用程序,我在服務器上使用Compojure,在客戶端上使用Clojurescript。 我正在使用leing-cljsbuild插件自動將cljs文件編譯為js。

當我將優化設置為:whitespace:simple ,我能夠生成所需的客戶端文件並在瀏覽器中加載它們,但是當我將優化設置為none時, js文件使用本地文件系統路徑引用它們的依賴項,這導致瀏覽器中根本沒有加載文件。

所以,我的問題是當clojurescript編譯器生成文件時,如何使生成的文件使用服務器URL而不是本地文件路徑。

這是我的project.clj文件

(defproject my-proj-clj "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"

  :dependencies [[org.clojure/clojure "1.5.1"]
                 [compojure "1.1.6"]
                 [org.clojure/tools.nrepl "0.2.3"]
                 [hiccup "1.0.3"]
                 [com.novemberain/monger "1.5.0"]
                 [org.clojure/clojurescript "0.0-2127"]
                 [jayq "2.5.0"]
                 ]

  :plugins [[lein-ring "0.8.8"]
            [lein-cljsbuild "1.0.1"] 
            ]

  :ring {:handler my-proj-clj.handler/app
                   }

  :cljsbuild { :builds 
              [{
                :source-paths ["src/my-proj-clj"]
                :compiler {
                           :output-dir "./resources/public/js"
                           :output-to "./resources/public/js/cljs-file.js"  
                           :pretty-print true
                           :source-map "./resources/public/js/cljs-file.js.map"
                           :optimizations :none
                           }}]}  

  :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]]}}

我相信唯一有效的優化值是:whitespace,:simple或:advanced。 請參閱https://github.com/emezeske/lein-cljsbuild/blob/1.0.1/sample.project.clj上的第96行。

因此我會使用:whitespace作為優化級別(至少可以使某些工作起作用)。

根據你的帖子,優化級別:空白有效嗎? 因此,也許你可以詳細說明。

您期望從“:none”的優化級別得到什么結果。 您的預期結果與以下優化級別:空白產生的結果有何不同?

優化級別:none表示cljsbuild不會從您的cljs源生成js(它將生成一些goog.include語句,但沒有其他內容)。 嘗試使用交互式repl來幫助您進行原型設計。 嘗試運行以下命令:lein trampoline cljsbuild repl-rhino

希望有所幫助。

我有大致相同的設置,優化設置為:none,生成的文件使用本地路徑。 但是,瀏覽器會加載腳本。

我在index.html有這個:

<script src="js/development/goog/base.js" type="text/javascript"></script>
<script src="js/development/main.js" type="text/javascript" ></script>
<script type="text/javascript">goog.require("ixtlan.core");</script>

這在project.clj

:cljsbuild {
  :builds [{:id "dev"
    :source-paths ["src/cljs"]
    :compiler {
      :output-to "resources/public/js/development/main.js"
      :output-dir "resources/public/js/development"
      :optimizations :none
      :source-map true}}
          ...

和路線包含:

(defroutes routes
  (GET "/" [] (index))
    (route/files "/" {:root "resources/public"}))

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM