简体   繁体   English

Clojure中的cljsbuild加载缓慢

[英]Slow loading of cljsbuild in Clojure

I'm new to Clojure and I'm trying to setup a development environment where I can dynamically load my web project files using ring-server and cljsbuild 我是Clojure的新手,我正在尝试建立一个开发环境,在这里我可以使用ring-server和cljsbuild动态加载Web项目文件

i have the following snippet in my project file 我的项目文件中包含以下代码段

:ring {
      :handler cjohansen-no.web/app
      ;;:auto-refresh true
      ;;:auto-reload? true
      ;;:reload-paths ["resources","src"]
      ;;:refresh-paths ["resources","src"]
    }
  :aliases {
        "start-server" ["ring" "server-headless"]
        "build-site" ["run" "-m" "cjohansen-no.web/export"]
        "build-html" ["run" "-m" "cjohansen-no.web/export-pages"]
        "build-js" ["cljsbuild" "auto" "dev"]
        "build-web" ["do" ["build-site"] ["build-js"]]
        "build-dev" ["pdo" ["build-web"] ["start-server"] ["auto" "build-html"]]
            }
  :source-paths ["src"]
  :test-paths ["test/cjohansen_no" "test/cljs" "spec"]
  :clean-targets [:target-path "./build/js/out"
                  :compile-path "classes"
                  :output-paths "./build/js/output"
                  "build/js/main.js.map"
                  ]
  :main cjohansen-no.web
  :clean-non-project-classes true
  :figwheel {
    ;;:server-port 3000
    :css-dirs ["resources/public/css"]
    :reload-clj-files {:clj true :cljc false}
    :ring-handler cjohansen-no.web/app
    :repl false
  }
  :cljsbuild {
    :builds [

      {
      ;; :notify-command ["growlnotify" "-m"]
      :id "dev"
      :source-paths ["src/cljs"]
      :figwheel {
          :websocket-host :js-client-host
          :autoload false
          :reload-dependents true
          :debug true
      }
      :compiler {
             :main scripts.core
             :output-to "resources/public/js/main.js"
             :output-dir "resources/public/js/out"
             :optimizations :none
             :source-map true
             :source-map-timestamp true
             :recompile-dependents false
             :pretty-print true
             :asset-path "js/out"

             ;;:notify-command ["bin/phantomjs"  "bin/speclj.js" "resources/public/js/main.js"]
           }

      }, 
....
}
  :profiles {
            :dev {
                :dependencies [
                  ;;[figwheel "0.5.4-7"]
                ]
                :plugins [
                    [lein-pdo "0.1.1"]
                    [lein-ring "0.9.7"]
                    [lein-cljsbuild "1.1.3"]
                    [lein-figwheel "0.5.4-7"]
                  ]
             }

I use this snippet to run my server 我使用此代码段运行服务器

(def app (->
            (stasis/serve-pages get-pages)
            (optimus/wrap get-assets optimizations/all serve-live-assets)
            ;;(wrap-cljsbuild "/js/" cljsbuild)
             wrap-content-type
             ;; wrap-reload
             wrap-utf-8))

I'm loading my assets using Optimus 我正在使用擎天柱加载资产

(defn get-assets []
  (concat (assets/load-bundle "public" "styles.css" [#"css/.+\.css$"])
    (assets/load-assets "public" [#"img/.*" "/questions.json"])
    (assets/load-bundle "public" "main.js" [#"js/.+\.js"])
    ))

when I run lein with-profile dev pdf start-server, cljsbuild auto and bring up my website the js files and its dependants as compiled by the "dev" build takes FOREVER to complete loading. 当我运行lein with-profile dev pdf start-server, cljsbuild auto打开我的网站,而“ dev”版本编译的js文件及其依赖项将永远需要完成加载。 Why is the ring server so slow? 为什么环形服务器这么慢?

Should I be referencing the build files in this manner? 我应该以这种方式引用构建文件吗? should i bundle it into one file? 我应该将其捆绑到一个文件中吗?

The profile used is for development purposes. 所使用的配置文件用于开发目的。

That is a pretty complex project.clj file if your just starting up and are new to clojure/clojurescript. 如果您刚刚起步并且对clojure / clojurescript不熟悉,那将是一个非常复杂的project.clj文件。 It is possible that starting with just the bare lein figwheel template might be a good way to get a basic environment and then just add to it once you know you need additional bits. 可能仅以光秃秃的lein figwheel模板开始可能是获得基本环境的好方法,然后在您知道需要更多位后再添加它。 It could be that simply parsing your project file is slowing things down. 可能仅仅是解析项目文件会减慢速度。

The basic figwheel template will set things up so that it all reloads when necessary - there really isn't much extra you need to worry about. 基本的Figwheel模板将进行设置,以便在必要时全部重新加载-实际上,您无需担心太多额外的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM