vbauer.lein-coffeescript

https://github.com/vbauer/lein-coffeescript.git

git clone 'https://github.com/vbauer/lein-coffeescript.git'

(ql:quickload :vbauer.lein-coffeescript)
7

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:

Installation

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

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: clojure :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

License

Copyright © 2014 Vladislav Bauer

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