# shadow-cljs - browser quickstart This is a minimum template you can use as the basis for CLJS projects intended to run in the browser. ## Required Software - [node.js v6.0.0+](https://nodejs.org/en/download/) - [Java8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) (Java9 has some issues, so stick with Java SE 8 for now). OpenJDK also works. ## Running the Example ```bash git clone https://github.com/shadow-cljs/quickstart-browser.git quickstart cd quickstart npm install npx shadow-cljs clj-repl ``` The first startup takes a bit of time since it has to download all the dependencies and do some prep work. Once this is running we can get started. ```txt (shadow/watch :app) ``` You do not have to do this at the REPL, you can also run `npx shadow-cljs watch app` in another terminal. The result will be the same. Either way you should see a message like this: ```txt [:app] Build completed. (23 files, 4 compiled, 0 warnings, 7.41s) ``` When you do you can start using the integrated development server to open the page in the browser. ```txt open http://localhost:8020 ``` The app is only a very basic skeleton with the most useful development tools configured. `shadow-cljs` is configured by the `shadow-cljs.edn` config. It looks like this: ```clojure {:source-paths ["src"] ;; .cljs files go here :dependencies [] ;; covered later :builds {:app {:target :browser :output-dir "public/js" :asset-path "/js" :modules {:main ;; <- becomes public/js/main.js {:entries [starter.browser]}} :devtools ;; before live-reloading any code call this function {:before-load starter.browser/stop ;; after live-reloading finishes call this function :after-load starter.browser/start ;; serve the public directory over http at port 8020 :http-root "public" :http-port 8020} }}} ``` It defines the `:app` build with the `:target` set to `:browser`. All output will be written to `public/js` which is a path relative to the project root (ie. the directory the `shadow-cljs.edn` config is in). `:modules` defines the how the output should be bundled together. For now we just want one file. The `:main` module will be written to `public/js/main.js`, it will include the code from the `:entries` and all their dependencies. `:devtools` configures some useful development things. The `http://localhost:8020` server we used earlier is controlled by the `:http-port` and serves the `:http-root` directory. `:before-load` and `:after-load` are useful callbacks that will be used by the devtools when live-reloading code. They are optional but they control the live-reload. If you do not need any callbacks just configure `:autoload true`. The last part is the actual `index.html` that is loaded when you open `http://localhost:8020`. It loads the generated `/js/main.js` and then calls `start.browser.init` which we defined in the `src/start/browser.cljs`. ```html