documentcloud/backbone — pull request #1685 by wookiehangover (2012-09-29 06:43:10+00:00)
Title: replace Rakefile with grunt.js

This patch replaces and updates the build process to leverage [grunt.js](http://gruntjs.com). Everything the Rakefile could do, grunt can do better!

The big changes in this commit are as follows:

* removes Rake, jsl, docco and closure-compiler binary dependencies
* grunt & grunt-docco are now "devDependencies" in package.json
* adds `node_modules` to .gitignore

In order to upgrade to grunt, there were a few related changes:

* JSHint uncovered 2 unsafely-unescaped values in regular expressions used in the router; these values are now properly escaped, all tests still pass back to IE8
* JSHint also uncovered an unnecessary semicolon after the declared Surrogate function
* The jsl config file in the docs directory was removed

### Motivation & Improvements

Grunt is a task-based build tool for JavaScript projects; Rake is a a simple ruby build program with capabilities similar to make. I'm usually a believer in the adage "don't fix it til its broken," but in this case I believe that this is a forward-thinking upgrade. There are several key advantages to using grunt:

* Backbone is now JavaScript from toe to tip, Ruby is no longer needed in the dev environment for any part of the build process
* Easy install with npm. Any new contributors can get all of the dependencies they need to run lint and headless tests with `npm install`.
* Qunit tests can be run in a headless phantomjs environment, and can be run automatically whenever test or source files are updated. This isn't a replacement for running tests in all browsers, but it does offer a simple and straight-forward workflow for quickly running (webkit-only) tests.
* JSHint is used for linting. This is also falls into the category "it-wasn't-broken-but-this-is-an-upgrade." JSLint is growing long in the tooth and required an additional binary dependency to run from the Rake task. This meant that contributors were unlikely to run `rake lint`, as evidenced by the state of the lint task in master (and v0.9.2 fwiw). Now, there's an easy way to configure lint options and programmatically enforce the project style-guide.
* Uglify-js is used for minification. Yet another "wasn't-really-broken" deal, but Uglify has been embraced by other large projects (jQuery, Twitter Bootstrap). Now that's not a reason in-and-of-itself to switch from the closure compiler, but its the default minification task in grunt it also removes another binary dependency required by the Rakefile.

Its been almost 2 years since the last material change to the build process, and in that time Node.js and the NPM ecosystem have grown immensely. Node now has tools that compete with and sometimes surpass what's offered by Ruby. For instance, this build process will work on any Windows machine with Node.js installed--not impossible to do with Ruby, but certainly *much* more complicated than installing the Node binary.

Grunt is an extremely sensible tool for managing JavaScript projects and a good fit for Backbone.