Skip to content

Commit

Permalink
add node example
Browse files Browse the repository at this point in the history
start adding examples of different figwheel behavior
  • Loading branch information
Bruce Hauman committed Jan 29, 2017
1 parent 01c5af7 commit 8069e64
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ example/figwheel_server.log
example/node_modules
example/server_out
example/target
examples/node-example/node_modules
examples/node-example/figwheel_server.log
examples/node-example/target
support/target
sidecar/target
plugin/target
Expand All @@ -36,6 +39,7 @@ pom.xml.asc
.lein-classpath
config.ru

figwheel_server.log
*~
*-init.clj
sidecar/figwheel_server.log
31 changes: 31 additions & 0 deletions examples/node-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# node-example

A simple figwheel node example.

Make sure you have ws installed

npm install ws

Start figwheel

lein figwheel

Start node

node target/js/compiled/node_example.js

Make sure your REPL isn't connecting to a browser.

Now you can interact in the REPL and edit and save `src/node_example/core.cljs`

## Things of note in the project.clj

In the `project.clj` you will see the build has `:target :nodejs`. It
is also important to set `:asset-path` so that you can launch node
from the root of the project.

## License

Copyright © 2014 FIXME

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
30 changes: 30 additions & 0 deletions examples/node-example/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(defproject node-example "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}

:min-lein-version "2.7.1"

:dependencies [[org.clojure/clojure "1.9.0-alpha14"]
[org.clojure/clojurescript "1.9.229"]]

:plugins [[lein-figwheel "0.5.9-SNAPSHOT"]]

:source-paths ["src"]

:cljsbuild {:builds
[{:id "node-dev"
:source-paths ["src"]
:figwheel true
:compiler {:main node-example.core
;; in order to call node from root of project
;; need to asset same as :output-dir
:asset-path "target/js/compiled/out"
:output-to "target/js/compiled/node_example.js"
:output-dir "target/js/compiled/out"
:source-map-timestamp true
;; !!! need to set the target to :nodejs !!!
:target :nodejs}}]}

)
17 changes: 17 additions & 0 deletions examples/node-example/src/node_example/core.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns node-example.core
(:require [cljs.nodejs :as nodejs]
[goog.object :as gobj]
[goog.string :as gstring]
[clojure.string :as string]))

(nodejs/enable-util-print!)

(println "Hello from the Node!")

(defn helper [] "hey there")

(def -main (fn [] nil))

(set! *main-cli-fn* -main)


0 comments on commit 8069e64

Please sign in to comment.