github
https://github.com/HuangChen1989/cljsinone
Why
- shadow-cljs 輕松整和了npm,安裝npm包和編譯只需幾行命令,支持live reload 和錯誤提示。
- 使用Vue 寫前端,html 加clojurescript 很輕松。
How
- 使用shadow-cljs 官方案例為基礎(chǔ) git clone 它
- 可以看到這是一個npm項目,而clojurescript 依賴 Java 安裝依賴包括 nodejs Java
-
npx shadow-cljs watch app這是啟動shadow-cljs 的命令,安裝依賴,更新包,打開nrepl, 開啟網(wǎng)頁服務(wù),一條命令完成 - 瀏覽器打開http://localhost:8020 就能看到hello world
- 安裝 Vue vue-router
- 修改
public/index.html
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Browser Starter</title>
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
<script src="/js/main.js"></script>
<script>starter.browser.init();</script>
</body>
</html>
- 修改
src/starter/browser.cljs
(ns starter.browser
(:require ["vue/dist/vue.js" :as Vue]
["vue-router/dist/vue-router.js" :as VueRouter]))
(defn ^:dev/after-load start []
(.use Vue VueRouter)
(js/console.log "start"))
(def Bar (clj->js {:template "<div>bar</div>"}))
(def routes (clj->js
[{:path "/bar" :component Bar}]))
(def router
(VueRouter. (clj->js {:routes routes})))
(defn app []
(Vue.
(clj->js
{:el "#app"
:router router})))
(defn ^:export init []
(js/console.log "init")
(start)
(app))
(defn ^:dev/before-load stop []
(js/console.log "stop"))