Support for src
This commit is contained in:
parent
98e30dae61
commit
57c4e38f7e
2
resources/public/cljs/script.cljs
Normal file
2
resources/public/cljs/script.cljs
Normal file
|
@ -0,0 +1,2 @@
|
|||
(defn foo []
|
||||
(println :foo))
|
|
@ -22,6 +22,7 @@
|
|||
(rdom/render [my-component] (.getElementById js/document "app"))
|
||||
</script>
|
||||
|
||||
<script src="cljs/script.cljs" type="application/x-sci"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -8,6 +8,17 @@
|
|||
(shell "clojure -M:dev -m shadow.cljs.devtools.cli release main")
|
||||
(def index-file (fs/file "gh-pages" "index.html"))
|
||||
|
||||
(def cljs-source-dir (fs/file "resources" "public" "cljs"))
|
||||
(def cljs-target-dir (fs/file "resources" "public" "cljs"))
|
||||
(fs/create-dirs cljs-target-dir)
|
||||
|
||||
(run! (fn [f]
|
||||
(println "Copying" (str f))
|
||||
(fs/copy f
|
||||
cljs-target-dir
|
||||
{:replace-existing true}))
|
||||
(fs/glob cljs-source-dir "*.cljs"))
|
||||
|
||||
(def js-source-dir (fs/file "resources" "public" "js"))
|
||||
(def js-target-dir (fs/file "gh-pages" "js"))
|
||||
(fs/create-dirs js-target-dir)
|
||||
|
|
|
@ -44,10 +44,23 @@
|
|||
(defn merge-ctx [opts]
|
||||
(swap! ctx sci/merge-opts opts))
|
||||
|
||||
(defn- load-contents [script-tags]
|
||||
(when-first [tag script-tags]
|
||||
(if-let [text (not-empty (gobject/get tag "textContent"))]
|
||||
(do (eval-string text)
|
||||
(load-contents (rest script-tags)))
|
||||
(let [src (.getAttribute tag "src")
|
||||
req (js/XMLHttpRequest.)
|
||||
_ (.open req "GET" src true)
|
||||
_ (gobject/set req "onload"
|
||||
(fn [] (this-as this
|
||||
(let [response (gobject/get this "response")]
|
||||
(eval-string response))
|
||||
(load-contents (rest script-tags)))))]
|
||||
(.send req)))))
|
||||
|
||||
(js/document.addEventListener
|
||||
"DOMContentLoaded"
|
||||
(fn []
|
||||
(let [script-tags (js/document.querySelectorAll "script[type='application/x-sci']")]
|
||||
(run! (fn [script-tag]
|
||||
(let [text (gobject/get script-tag "textContent")]
|
||||
(eval-string text))) script-tags))), false)
|
||||
(load-contents script-tags))), false)
|
||||
|
|
Loading…
Reference in a new issue