|
132 | 132 | "<script src=\"" output-to "\"></script>" |
133 | 133 | "</body></html>")) |
134 | 134 |
|
135 | | -(defn send-static [{path :path :as request} conn {:keys [static-dir host port gzip?] :as opts}] |
| 135 | +(defn send-static |
| 136 | + [{path :path :as request} conn |
| 137 | + {:keys [static-dir output-to output-dir host port gzip?] :or {output-dir "out"} :as opts}] |
136 | 138 | (if (and static-dir (not= "/favicon.ico" path)) |
137 | 139 | (let [path (if (= "/" path) "/index.html" path) |
138 | 140 | local-path |
|
151 | 153 | (#{"/cljs-logo-icon-32.png" "/cljs-logo.svg"} path) |
152 | 154 | (io/resource (subs path 1)) |
153 | 155 | :else nil) |
154 | | - local-path) |
155 | | - copts (when env/*compiler* (get @env/*compiler* :options))] |
| 156 | + local-path)] |
156 | 157 | (cond |
157 | 158 | local-path |
158 | 159 | (if-let [ext (some #(if (.endsWith path %) %) (keys ext->mime-type))] |
|
163 | 164 | (server/send-and-close conn 200 (slurp local-path) "text/plain")) |
164 | 165 | ;; "/index.html" doesn't exist, provide our own |
165 | 166 | (= path "/index.html") |
166 | | - (let [{:keys [output-to] :or {output-to "out/main.js"}} copts] |
167 | | - (server/send-and-close conn 200 (default-index output-to) "text/html" "UTF-8")) |
168 | | - (= path "/out/main.js") |
| 167 | + (server/send-and-close conn 200 |
| 168 | + (default-index (or output-to (str output-dir "/main.js"))) "text/html" "UTF-8") |
| 169 | + (= path (str "/" output-dir "/main.js") ) |
169 | 170 | (let [closure-defines (-> `{clojure.browser.repl/HOST ~host |
170 | 171 | clojure.browser.repl/PORT ~port} |
171 | 172 | cljsc/normalize-closure-defines |
172 | 173 | json/write-str)] |
173 | 174 | (server/send-and-close conn 200 |
174 | 175 | (str "var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n" |
175 | 176 | "var CLOSURE_NO_DEPS = true;\n" |
176 | | - "document.write('<script src=\"out/goog/base.js\"></script>');\n" |
177 | | - "document.write('<script src=\"out/goog/deps.js\"></script>');\n" |
178 | | - (when (.exists (io/file "out" "cljs_deps.js")) |
179 | | - "document.write('<script src=\"out/cljs_deps.js\"></script>');\n") |
180 | | - "document.write('<script src=\"out/brepl_deps.js\"></script>');\n" |
| 177 | + "document.write('<script src=\"" output-dir "/goog/base.js\"></script>');\n" |
| 178 | + "document.write('<script src=\"" output-dir "/goog/deps.js\"></script>');\n" |
| 179 | + (when (.exists (io/file output-dir "cljs_deps.js")) |
| 180 | + "document.write('<script src=\"" output-dir "/cljs_deps.js\"></script>');\n") |
| 181 | + "document.write('<script src=\"" output-dir "/brepl_deps.js\"></script>');\n" |
181 | 182 | "document.write('<script>goog.require(\"clojure.browser.repl.preload\");</script>');\n") |
182 | 183 | "text/javascript" "UTF-8")) |
183 | 184 | :else (server/send-404 conn path))) |
|
300 | 301 | ;; TODO: this could be cleaner if compiling forms resulted in a |
301 | 302 | ;; :output-to file with the result of compiling those forms - David |
302 | 303 | (when (and output-dir (not (.exists (io/file output-dir "clojure" "browser" "repl" "preload.js")))) |
303 | | - (spit (io/file "out/brepl_deps.js") |
304 | | - (build/build |
305 | | - '[(require '[clojure.browser.repl.preload])] |
306 | | - {:optimizations :none |
307 | | - :opts-cache "brepl_opts.edn"}))) |
| 304 | + (let [target (io/file output-dir "brepl_deps.js")] |
| 305 | + (util/mkdirs target) |
| 306 | + (spit target |
| 307 | + (build/build |
| 308 | + '[(require '[clojure.browser.repl.preload])] |
| 309 | + {:optimizations :none |
| 310 | + :output-dir output-dir |
| 311 | + :opts-cache "brepl_opts.edn"})))) |
308 | 312 | (repl/err-out |
309 | 313 | (println "Serving HTTP on" (:host repl-env) "port" (:port repl-env)) |
310 | 314 | (println "Listening for browser REPL connect ...")) |
|
0 commit comments