Skip to content

Instantly share code, notes, and snippets.

@kohyama
Last active February 6, 2021 12:41
Show Gist options
  • Save kohyama/6183122 to your computer and use it in GitHub Desktop.
Save kohyama/6183122 to your computer and use it in GitHub Desktop.

Revisions

  1. kohyama revised this gist Aug 9, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,7 @@ 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](https://gist.github.com/kohyama/6191281).

    ### 5. Use it
    ```
  2. kohyama revised this gist Aug 9, 2013. 4 changed files with 35 additions and 25 deletions.
    44 changes: 29 additions & 15 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,56 @@
    # A minimum setting to use browser REPL of ClojureScript
    ## A minimum setting to use browser REPL of ClojureScript

    Assumed that you have set [leiningen](https://github.com/technomancy/leiningen) up and can use it.

    1. Copy files or git clone this gist and move or copy repl-test.cljs
    under `src` directory
    ### 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 `repl-test.cljs` into `js/repl-test.js`
    ### 2. Compile
    Compile `repl-test.cljs` into `brepl-test.js`.
    ```
    $ lein cljsbuild once
    ```

    3. Run a ClojureScript REPL
    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 is a minimum web server serving `index.html` and JavaScript files
    under `js` directory.
    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
    ```

    4. Open index.html on web browser
    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
    ```
    http://localhost:9000/
    No 'xpc' param provided to child iframe.
    ```
    Note
    * `index.html` should be in the same directory in which project.clj is.
    * An html file nameed other than `index.html` doesn't work.
    * Openning as a local file with `file:` doesn't work.
    * Outputting compiled js files to a directory other than js doesn't work.
    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.

    5. Use it
    ### 5. Use it
    ```
    ClojureScript:cljs.user> (js/alert "Hello world from CLJS REPL!")
    ```
    5 changes: 5 additions & 0 deletions brepl-test.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <html>
    <body>
    <script type="text/javascript" src="brepl-test.js"></script>
    </body>
    </html>
    7 changes: 0 additions & 7 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" src="js/repl-test.js"></script>
    </body>
    </html>
    4 changes: 1 addition & 3 deletions project.clj
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,4 @@
    :builds [{
    :source-paths ["src"]
    :compiler {
    :output-to "js/repl-test.js"
    :optimizations :whitespace
    :pretty-print true}}]})
    :output-to "brepl-test.js"}}]})
  3. kohyama revised this gist Aug 8, 2013. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -21,21 +21,20 @@ $ lein cljsbuild once
    $ lein trampoline cljsbuild repl-listen
    Running ClojureScript REPL, listening on port 9000.
    "Type: " :cljs/quit " to quit"
    ClojureScript:cljs.user>
    ClojureScript:cljs.user>
    ```
    This is a minimum web server serving `index.html` and JavaScript files
    under `js` directory.

    4. Open index.html on web browser
    4. Open index.html on web browser
    ```
    http://localhost:9000/
    ```
    Note

    * `index.html` should be in the same directory in which project.clj is.
    * An html file nameed other than `index.html` doesn't work.
    * Openning as a local file with `file:` doesn't work.
    * Outputting compiled js files to a directory other than js doesn't work.
    * `index.html` should be in the same directory in which project.clj is.
    * An html file nameed other than `index.html` doesn't work.
    * Openning as a local file with `file:` doesn't work.
    * Outputting compiled js files to a directory other than js doesn't work.

    5. Use it
    ```
  4. kohyama revised this gist Aug 8, 2013. 1 changed file with 45 additions and 0 deletions.
    45 changes: 45 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # A minimum setting to use browser REPL of ClojureScript

    Assumed that you have set [leiningen](https://github.com/technomancy/leiningen) up and can use it.

    1. Copy files 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 `repl-test.cljs` into `js/repl-test.js`
    ```
    $ lein cljsbuild once
    ```

    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 is a minimum web server serving `index.html` and JavaScript files
    under `js` directory.

    4. Open index.html on web browser
    ```
    http://localhost:9000/
    ```
    Note

    * `index.html` should be in the same directory in which project.clj is.
    * An html file nameed other than `index.html` doesn't work.
    * Openning as a local file with `file:` doesn't work.
    * Outputting compiled js files to a directory other than js doesn't work.

    5. Use it
    ```
    ClojureScript:cljs.user> (js/alert "Hello world from CLJS REPL!")
    ```
    If the web browser pops an alert window up, it works.

  5. kohyama renamed this gist Aug 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. kohyama revised this gist Aug 8, 2013. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@
    <head>
    </head>
    <body>
    <script type="text/javascript" src="/js/repl-test.js"></script>
    <script type="text/javascript" src="js/repl-test.js"></script>
    </body>
    </html>
    File renamed without changes.
  7. Kei Tsuji renamed this gist Aug 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. Kei Tsuji revised this gist Aug 8, 2013. 4 changed files with 8 additions and 8 deletions.
    7 changes: 7 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" src="/js/repl-test.js"></script>
    </body>
    </html>
    2 changes: 1 addition & 1 deletion project.clj
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@
    :builds [{
    :source-paths ["src"]
    :compiler {
    :output-to "repl-test.js"
    :output-to "js/repl-test.js"
    :optimizations :whitespace
    :pretty-print true}}]})
    7 changes: 0 additions & 7 deletions repl-test.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" src="repl-test.js"></script>
    </body>
    </html>
    File renamed without changes.
  9. Kei Tsuji revised this gist Aug 8, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion project.clj
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@
    :builds [{
    :source-paths ["src"]
    :compiler {
    :output-to "repl-test.js"
    :output-to "js/repl-test.js"
    :optimizations :whitespace
    :pretty-print true}}]})
  10. Kei Tsuji renamed this gist Aug 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. Kei Tsuji revised this gist Aug 8, 2013. 2 changed files with 7 additions and 7 deletions.
    7 changes: 7 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" src="/js/repl-test.js"></script>
    </body>
    </html>
    7 changes: 0 additions & 7 deletions repl-test.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" src="repl-test.js"></script>
    </body>
    </html>
  12. kohyama revised this gist Aug 8, 2013. 2 changed files with 3 additions and 5 deletions.
    5 changes: 1 addition & 4 deletions repl-test.cljs
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,4 @@
    (ns repl-test
    (:require [clojure.browser.repl :as repl]
    [goog.dom :as dom]
    [goog.events :as events]
    [goog.events.EventType :as event-type]))
    (:require [clojure.browser.repl :as repl]))

    (repl/connect "http://localhost:9000/repl")
    3 changes: 2 additions & 1 deletion repl-test.html
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    <html>
    <head></head>
    <head>
    </head>
    <body>
    <script type="text/javascript" src="repl-test.js"></script>
    </body>
  13. kohyama revised this gist Aug 8, 2013. 3 changed files with 15 additions and 3 deletions.
    9 changes: 9 additions & 0 deletions project.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    (defproject repl-test "0.1.0-SNAPSHOT"
    :plugins [[lein-cljsbuild "0.3.2"]]
    :cljsbuild {
    :builds [{
    :source-paths ["src"]
    :compiler {
    :output-to "repl-test.js"
    :optimizations :whitespace
    :pretty-print true}}]})
    3 changes: 0 additions & 3 deletions repl-test.cljs
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,3 @@
    [goog.events.EventType :as event-type]))

    (repl/connect "http://localhost:9000/repl")

    (defn ^:export init []
    (.log js/console "foo"))
    6 changes: 6 additions & 0 deletions repl-test.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <html>
    <head></head>
    <body>
    <script type="text/javascript" src="repl-test.js"></script>
    </body>
    </html>
  14. kohyama created this gist Aug 8, 2013.
    10 changes: 10 additions & 0 deletions repl-test.cljs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    (ns repl-test
    (:require [clojure.browser.repl :as repl]
    [goog.dom :as dom]
    [goog.events :as events]
    [goog.events.EventType :as event-type]))

    (repl/connect "http://localhost:9000/repl")

    (defn ^:export init []
    (.log js/console "foo"))