unepwcmc/NRT — pull request #290 by adammulligan (2014-02-17 08:08:17+00:00)
Title: Asset pipeline

Morning,

I was NodeJSing this weekend and playing around with connect-assets, and thought I'd get it implemented in NRT. Turns out connect-assets only works for Less and Stylus templates, so I thought I'd use the time to instead speed up the grunt compilation. I made some really good progress, and now there's no requirement to hit refresh a few hundred times before you can see a change you made to the client code.

Server and client tests are passing, and the application looks to be working as it was before I touched anything, though I think this is definitely a pull request where pulling the changes and taking a look yourself is a good idea :)

### What this means

* `grunt && grunt watch` still needs to be running for concatenation. In production you just run `grunt` as normal.
* Coffee source doesn't need to be compiled on every change, just concatenated (very quick, ~0.3s). A coffee middleware handles streaming compilation.
* Sass source doesn't need to be compiled on every change, Nesbitt's `node-sass` middleware does it on request a la asset-pipeline
* As Grunt watches templates, coffee source and tests separately so a change to any of those doesn't require the entire application to be recompiled
* Supervisor no longer watches the `server/public` directory. This means the server does not restart when the client code changes, which drastically reduces the number of times you have to hit refresh. **I think this tiny change is where we've gained the biggest "compile" time improvements**

### Downsides

* Each page that uses the backbone app also has to manually include the compiled `templates.js`. I don't think this is so bad since we already include so much javascript manually. The reason for this is so that we can stream the application as coffeescript, which means we can't concatenate the templates in as handlebars outputs plain old JS.
* Had to move `client/src/sass` to `client/src/css` because of node-sass's search path