techpines/asset-rack — pull request #109 by bryanchriswhite (2013-11-02 05:05:47+00:00)
Title: Add `prepend` option to BrowserifyAsset and update readme

### Synopsis:
Adds an optional `prepend` option to `BrowserifyAsset`. This will allow the Browserify asset to include another javascript asset at the beginning of the file it generates.

### Use Case:
A specific use case is discussed in issue #82 and in conjunction with PR #107 should allow for a single asset to serve a bundle of all of a client apps JS files **and** it's templates via a single script tag.

### Example:
_The example project described below can be found [here](https://github.com/bryanchriswhite/AssetRackExample)_

File System:
```
AssetRackExample
├── app.js
├── assets.js
├── public
│ ├── index.html
└── widget
├── app
│ ├── controllers
│ │ └── index.js
│ ├── directives
│ ├── index.js
│ └── views
│ ├── view1.html
│ └── view2.html
└── test
├── e2e
└── spec
```

#### Server
In assets.js (/assets.js):
```javascript
var rack = require('asset-rack')
, assets = new rack.Rack([
new rack.BrowserifyAsset({
url : '/js/widget.bundle.js',
filename: __dirname + '/widget/app/index.js',
prepend : new rack.AngularTemplatesAsset({
url : '/js/widget/templates.js',
dirname: __dirname + '/widget/app/views'
})
})
])
;

module.exports = assets;
```

In app.js (/app.js):
```javascript
var assets = require('./assets');
app.use(assets);
```

#### Client
In index.html (public/index.html):
```html

```

In index.js (widget/app/index.js):
```javascript
angular.module('myApp', [])
.config([
'$routeProvider', function($routeProvider) {
$routeProvider
.when('/one', {
templateUrl: 'view1.html',
controller : 'MainCtrl'
})
.when('/two', {
templateUrl: 'view2.html',
controller : 'MainCtrl'
})
}
])
.run(['$templateCache', angularTemplates]);
require('./controllers');
```

Should wrap up issue #82