How to Create ClojureScript App
The goal of those tools is to provide build setup with no configuration, so it’s easier to get started for developers and newbies. In this article I’d like to make a short overview of what ClojureScript can offer for those who is just starting with the language.
Leiningen is the easiest way to use Clojure. With a focus on project automation and declarative configuration, it gets out of your way and lets you focus on your code.
That’s it! All you need is a single tool. Leiningen manages your dependencies, runs development server and makes production builds. It is actually the most essential tool for Clojure(Script) projects. It allows to use CSS preprocessors, lint you code, run e2e tests or deploy to production and do much more tasks with plugins. You can think of Leiningen as a task runner like Grunt.
Leiningen eliminates configuration boilerplate using templates. A template is a package written by random person on the internet, to help other developers get started with different types of projects.
- Install Leiningen (see other installation options):
brew install lein
2. Bootstrap ClojureScript project with Figwheel template:
lein new figwheel project-name
This will generate a project of the following structure:
│ └── user.clj
│ └── public
│ ├── css
│ │ └── style.css
│ └── index.html
lein new figwheel project-name -- --rum
lein cljsbuild once min
lein-cljsbuild is a plugin for building ClojureScript projects.
Let’s have a look on what’s going on here:
- Configuration validation. If something is wrong with a config, Figwheel will ask you to fix this by pointing to exact error in config file.
- Starting server. Development server is starting at locahost:3449, port can be specified in config.
- Starting CSS watcher. Simple watcher for CSS files that will push changes into browser.
- ClojureScript REPL. At last Figwheel will start interactive REPL where you can run code that will be executed in browser and interact with project’s code.
I’ve recorded this quick video to show how REPL and Figwheel works.
Clojure(Script) packages are stored in repository similar to NPM, it’s called Clojars. You can find a package there and add it into :dependencies in your project.clj. Leiningen will install new dependencies automatically, when you restart the project.
:dependencies [[org.clojure/core.async "0.2.391"]]
I hope this article will make you less afraid of ClojureScript and help to get started with it in seconds. Below is a list of resources which you might want to read to learn more about language and tools.