Leiningenの導入
まずはbuild toolの導入です。
https://github.com/technomancy/leiningen
からスクリプトをダウンロードしましょう。
- Linux
- Installationの"Download the script"
- Windows
- Installationの"the batch file"
ターミナルを立ち上げて
lein self-install
が実行出来ればleiningenの導入は完了です。
Projectの作成
ターミナルで
lein new cljstest
と打ちましょう。
cljstestというプロジェクトが作られます。
作られたプロジェクトのディレクトリには、project.cljが存在します。
これを以下のように書き換えて下さい。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject cljstest "1.0.0-SNAPSHOT" | |
:dependencies [[org.clojure/clojure "1.4.0"]] | |
:plugins [[lein-cljsbuild "0.1.8"]] | |
:cljsbuild { | |
:builds [{ | |
:source-path "src" | |
:compiler { | |
:output-to "main.js" | |
:optimizations :whitespace | |
:pretty-print true}}]}) |
詳しい設定の仕方は
https://github.com/emezeske/lein-cljsbuild
編集ができたら
lein deps
lein cljsbuild auto
を実行して下さい。
core.cljsの編集
cljstest/src/cljstestに存在するcore.cljをcore.cljsにリネームし、以下のように編集します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cljstest.core) | |
(.alert js/window "Hello") |
ファイルを保存すると自動でコンパイルされ、 cljstestにmain.jsが作成されます。
以下のようなhtmlファイルをcljstestに作り、実行してみましょう。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>cljstest</title> | |
</head> | |
<body> | |
<script type="text/javascript" src="main.js"></script> | |
</body> | |
</html> |
アラートが出れば完成です。