Skip to content

Instantly share code, notes, and snippets.

@kohyama kohyama/README.md
Last active Jan 25, 2018

Embed
What would you like to do?
A minimum setting to use browser REPL of ClojureScript

A minimum setting to use browser REPL of ClojureScript

Assumed that you have set leiningen up and can use it.

1. Prepare files

Copy project.clj, repl-test.cljs and brepl-test.html from this gist or git clone this gist and move or copy repl-test.cljs under src directory.

$ git clone https://gist.github.com/6183122.git
$ cd 6183122/
$ mkdir src
$ mv repl-test.cljs src/

2. Compile

Compile repl-test.cljs into brepl-test.js.

$ lein cljsbuild once

Note that a JavaScript file whose name starts with repl raises an error like

Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:9000/repl-test.js".

at step 4.

3. Run a ClojureScript REPL

$ lein trampoline cljsbuild repl-listen
Running ClojureScript REPL, listening on port 9000.
"Type: " :cljs/quit " to quit"
ClojureScript:cljs.user>

This repl also works as a lightweight web server serving the project directory as the document root.

4. Open the HTML file

Open brepl-test.html on a web browser via the repl web server.

http://localhost:9000/brepl-test.html

Note that openning as a local file with file: doesn't work.
Also note that a HTML file whose name starts with repl raises an error like

No 'xpc' param provided to child iframe.

Of course, it's O.K. to serve HTML and JavaScript files with whatever web server you like. In the case, HTML and JavaScript file whose name starts with repl isn't inhibitted. Refer how to use browser REPL of ClojureScript with compojure.

5. Use it

ClojureScript:cljs.user> (js/alert "Hello world from CLJS REPL!")

If the web browser pops an alert window up, it works.

<html>
<body>
<script type="text/javascript" src="brepl-test.js"></script>
</body>
</html>
(defproject repl-test "0.1.0-SNAPSHOT"
:plugins [[lein-cljsbuild "0.3.2"]]
:cljsbuild {
:builds [{
:source-paths ["src"]
:compiler {
:output-to "brepl-test.js"}}]})
(ns repl-test
(:require [clojure.browser.repl :as repl]))
(repl/connect "http://localhost:9000/repl")
@kohyama

This comment has been minimized.

Copy link
Owner Author

commented Aug 8, 2013

Thanks to @swannodette, @ktsujister and @otabat_
https://twitter.com/kohyama/status/365409226425761792
now it runs.

Environment:
Mac OS X Snow Leopard
Leiningen 2.2.1-SNAPSHOT on Java 1.6.0_51 Java HotSpot(TM) 64-Bit Server VM
Google Chrome 28.0.1500.95

@kohyama

This comment has been minimized.

Copy link
Owner Author

commented Aug 9, 2013

Far more example: Code, Screen cast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.