weavejester / lein-ring

Ring plugin for Leiningen
Eclipse Public License 1.0
501 stars 100 forks source link

lein doesn't :auto-refresh :auto-reload #174

Closed karneaud closed 8 years ago

karneaud commented 8 years ago

Have been trying to automate my ring server without success the following is a snippet my project.clj

:dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.89"]
                 [stasis "2.2.0"]
                 [ring "1.5.0"]
                 [ring/ring-json "0.4.0"]
                 [ring/ring-defaults "0.2.0"]
                 [hiccup "1.0.5"]
                 [enlive "1.1.5"]
                 [clj-tagsoup "0.3.0"]
                 [optimus "0.18.5"]
                 [ring-cljsbuild "2.1.3"]
                 [org.clojure/tools.logging "0.2.6"]
                 [cljs-ajax "0.5.8"]
                 [enfocus "2.1.1"]
                 ]
  :plugins [
    [lein-ring "0.9.7"]
    [lein-cljsbuild "1.1.3"]
  ]
:ring {
      :handler cjohansen-no.web/app
      :auto-refresh? true
      :auto-reload? true
      :reload-paths ["src"]
      ;; :refresh-paths ["resources/pages" "src/cjohansen_no/hiccup_templating"]
    }

server side

(def app (->
            (stasis/serve-pages get-pages) ;; gets my pages via directory/ routing
            (optimus/wrap get-assets optimizations/all serve-live-assets) ;; get my assets from folder
             wrap-content-type
             wrap-reload
             wrap-utf-8))

what could be the problem? I saw that there were similar issues ....were these bug fixed?

weavejester commented 8 years ago

Could you provide more information on what problem you're having? You're expecting it to reload when namespaced Clojure files are changed, right?

Could you also provide a sample project that replicates the issue?

karneaud commented 8 years ago

here is my project I'm trying to understand your documentation but it seems so vague in its statements..

weavejester commented 8 years ago

I'll take a look. What parts are vague?

karneaud commented 8 years ago

how the auto-reload and refresh are used and works....does it only do clj? cljs? can you define multiple paths? where does it get its path from? as defined in the project.clj?

weavejester commented 8 years ago

Well, :auto-reload? "automatically reload modified source files", while auto-refresh? "automatically refresh the browser when source or resource files are modified".

So :auto-reload? only works with Clojure files. It reloads files on the server. :auto-refresh? looks for any changes to source or resource files. Typically this means any file in src and resources.

I've checked out your project. The reason it's not working is because your js/main.js file is throwing an error. This appears to be stopping the refresh script from running. If you remove your script tag, then the auto-refresh behavior starts working again.

Incidentally, since you're using ClojureScript, have you considered using Figwheel?

karneaud commented 8 years ago

@weavejester been trying to use fig wheel but it is nothing meeintg my needs as I need to watch more than just clj files and seems to render the :auto-reload and :auto-refresh triggers useless. I'm new to the clojure language and wanted to fiddle around with the basics before i get committed with frameworks

if I remove the script tag then how will my code work?

weavejester commented 8 years ago

Well, ideally you should fix your script. Your script is throwing an error, and this is stopping the :auto-refresh? behavior from working.

karneaud commented 8 years ago

@weavejester just did.....still no refresh OR reload with both options set to true. Is it that I need to specify paths in the ring options? because I specify them only in the project root config.

karneaud commented 8 years ago

Tried editing the file src/clj/templates/footer.clj....not sure what I'm doing wrong at this point

weavejester commented 8 years ago

It's your ClojureScript that's causing the problem. It looks like it's throwing an error in your repl-connect function.

However, I believe the ultimate cause of your refresh issues is because both your script and the Ring-Refresh library are attempting to set the onload property of the window. Effectively your script is overriding the refresh script.

The Ring-Refresh script should be more robust, ideally, but you can work around this problem by using addEventListener instead:

(.addEventListener js/window "load" #(do (em/wait-for-load (init)) (repl-connect)))
karneaud commented 8 years ago

Thanks man! that really did the trick....can't believe that it was this causing the issue all along!