re-frame的 template 为例,搭建 clojurescript 开发环境。

基础环境: Ubuntu 20.04 + jdk 11

安装clj命令行工具

按照clojure官网的方法安装 clj.

安装 Idea Intellij + Cursive

可以使用 Idea Intellij 的 community 版本。 安装完成后,安装 cursive 插件,其 license 可以去官网获取免费的个人版。

创建项目

reframe的模板项目为基础创建一个新的 cljs 项目:

1
lein new re-frame my-app

创建完成后,打开项目目录,会发现默认使用 shadow 来管理依赖,配置记录在shadow-cljs.edn中。 现在我们改为使用 deps 来管理。 创建deps.edn文件,内容为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
 :paths   ["dev"]
 :deps    {thheller/shadow-cljs {:mvn/version "2.12.5"}}

 :aliases {:cljs
           {:extra-deps  {reagent            {:mvn/version "1.0.0"}
                          re-frame           {:mvn/version "1.2.0"}
                          binaryage/devtools {:mvn/version "1.0.3"}
                          }
            :extra-paths ["src/main" "src/test"]
            }
           }
 }

shadow-cljs.edn 中,添加:

1
 :deps  {:aliases [:cljs]}

shadow-cljs 将使用 deps 来管理依赖。

在 intellij 中打开项目时,选择 打开-> 从已有资源打开,然后选择deps.edn文件,以项目形式打开。

clojure deps面板中,选中我们设定的别名配置cljs:

clojure deps

然后在外部库上右键,选择Refresh Clojure Deps Project,即可添加外部库。

refresh deps

启动项目,添加 repl

在 intellij 中添加一个运行配置,选择本地 clojure repl:

clojure repl

启动项目:

1
yarn && yarn watch

之后,运行repl,在其中即可运行命令。 默认连接的是 clojure 的 repl,可以运行 (shadow/node-repl)来切换到 node 的 repl。

node repl