A Leiningen plugin for running CoffeeScript compiler
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
src
test/lein_coffeescript
.gitignore
.travis.yml
LICENSE
README.md
project.clj

README.md

lein-coffeescript

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.

lein-coffeescript is a Leiningen plugin that allows to use CoffeeScript compiler.

Build Status Clojars Project

Pre-requirements

Install NodeJS and NPM (package manager for Node) to install CoffeeScript:

  • On Ubuntu: sudo apt-get install nodejs
  • On Mac OS X: brew install node

Installation

Install CoffeeScript to use lein-coffeescript plugin. It could be done in few ways:

  • Use NPM to install CoffeeScript globally: npm install coffee-script -g
  • You can also install CoffeeScript in the current directory: npm install coffee-script
  • Use lein-npm plugin: lein npm install
  • Use just Leiningen: lein deps

Setup

To enable lein-coffeescript for your project, put the following in the :plugins vector of your project.clj file:

; Use latest version instead of "X.X.X"
:plugins [[lein-coffeescript "X.X.X"]]

Configuration

To configure lein-coffeescript, put the :coffeescript parameter in the file project.clj. It could be a single configuration (simple map) or a collection of configurations (for multiple configuration).

; single configuration
:coffeescript {:sources "src/*.cs"}

; multiple configurations
:coffeescript [{:sources "src/*.cs"
                :bare false
                :map true}
               {:sources ["src/*.coffee" "resources/*.cs"]
                :bare true}]

Configuration parameters

:sources
List of input CoffeeScript sources. It is possible to use a single source or a vector of sources. To configure this parameter, you could also use a Glob Patterns.
:excludes
List of glob patterns to prevent processing of some files. It is also possible to use both variants: single pattern and collection of patterns.
:map
Generate source maps alongside the compiled JavaScript files. Adds sourceMappingURL directives to the JavaScript as well. Default value: false.
:bare
Compile the JavaScript without the top-level function safety wrapper. Default value: false
:join
Before compiling, concatenate all scripts together in the order they were passed, and write them into the specified file. Useful for building large projects. It is not defined by default. Example: `:join "bundle.coffee"`.
:output
Write out all compiled JavaScript files into the specified directory. It is not defined by default. Source directory will be used of generated JS files.
:watch
Watch files for changes, rerunning the specified command when any file is updated. Default value: false

Hooks

To enable this plugin in the compile stage, use the following hook:

:hooks [lein-coffeescript.plugin]

Examples

Detailed example

:coffeescript {:sources "resources/*.coffee"
               :excludes ["resources/tests.coffee" "resources/bad.coffee"]
               :map true
               :join "app.js"
               :output "target/js"
               :bare false
               :debug true}

Example project

Just clone the current repository and try to play with example project for better understanding how to use lein-coffeescript.

Usage

To compile CoffeeScript files using configuration from project.clj, you should use: lein coffeescript

To show help: lein help coffeescript

Unit testing

To run unit tests:

lein test

Thanks to

CoffeeScript author Jeremy Ashkenas and other developers who worked on this great project.

Might also like

  • lein-typescript - a Leiningen plugin for running TypeScript compiler.
  • lein-jslint - a Leiningen plugin for running javascript code through JSLint.
  • lein-jshint - a Leiningen plugin for running javascript code through JSHint.
  • lein-plantuml - a Leiningen plugin for generating UML diagrams using PlantUML.
  • lein-asciidoctor - A Leiningen plugin for generating documentation using Asciidoctor.
  • jabberjay - a simple framework for creating Jabber bots.
  • coderwall-clj - a tiny CoderWall client for Clojure.

License

Copyright © 2014 Vladislav Bauer

Distributed under the Eclipse Public License, the same as Clojure.