caolan/jam — pull request #112 by toddb (2012-11-30 21:34:26+00:00)
Title: Additional requirejs configuration from package.json

`Rebuild` command has been extended to include from `config` section in the `package.json`. It is merged with jam packages and shims in `require.config.js`. The output from rebuild has been slightly changed to be compatible with `r.js` compilation.

## Browser packages in package.json

You can also define your browser dependencies in a project-level package.json
file. If you use Node.js, this format will already familiar to you, and the
Jam dependencies can live alongside your NPM dependencies. It's also possible
to define custom install paths and baseUrls, as well as hand in any requirejs
configuration here:

```javascript
{
"name": "my-project",
"version": "0.0.1",
"description": "My example project",
"jam": {
"baseUrl": "public",
"packageDir": "public/vendor",
"dependencies": {
"jquery": "1.7.x",
"underscore": null
},
"config": {
"paths": {
"templates": "public/templates"
}
}
}
}
```

### Output: require.config.js

(fixed for r.js - it doesn't work with variable substitution)

```javascript
var jam = {
"packages": [
{
"name": "backbone",
"location": "vendor/backbone",
"main": "backbone.js"
},
{
"name": "bootstrap",
"location": "vendor/bootstrap"
},
{
"name": "jquery",
"location": "vendor/jquery",
"main": "jquery.js"
},
{
"name": "lodash",
"location": "vendor/lodash",
"main": "./lodash.js"
},
{
"name": "text",
"location": "vendor/text",
"main": "text.js"
},
{
"name": "underscore",
"location": "vendor/underscore",
"main": "underscore.js"
},
{
"name": "underscore.string",
"location": "vendor/underscore.string",
"main": "./lib/underscore.string"
}
],
"version": "0.2.11",
"shim": {
"backbone": {
"deps": [
"jquery",
"lodash"
],
"exports": "Backbone"
}
}
};

if (typeof require !== "undefined" && require.config) {
require.config({
"paths": {
"templates": "public/templates"
},
"packages": [
{
"name": "backbone",
"location": "vendor/backbone",
"main": "backbone.js"
},
{
"name": "bootstrap",
"location": "vendor/bootstrap"
},
{
"name": "jquery",
"location": "vendor/jquery",
"main": "jquery.js"
},
{
"name": "lodash",
"location": "vendor/lodash",
"main": "./lodash.js"
},
{
"name": "text",
"location": "vendor/text",
"main": "text.js"
},
{
"name": "underscore",
"location": "vendor/underscore",
"main": "underscore.js"
},
{
"name": "underscore.string",
"location": "vendor/underscore.string",
"main": "./lib/underscore.string"
}
],
"shim": {
"backbone": {
"deps": [
"jquery",
"lodash"
],
"exports": "Backbone"
}
}
});
}
else {
var require = {
"paths": {
"templates": "public/templates"
},
"packages": [
{
"name": "backbone",
"location": "vendor/backbone",
"main": "backbone.js"
},
{
"name": "bootstrap",
"location": "vendor/bootstrap"
},
{
"name": "jquery",
"location": "vendor/jquery",
"main": "jquery.js"
},
{
"name": "lodash",
"location": "vendor/lodash",
"main": "./lodash.js"
},
{
"name": "text",
"location": "vendor/text",
"main": "text.js"
},
{
"name": "underscore",
"location": "vendor/underscore",
"main": "underscore.js"
},
{
"name": "underscore.string",
"location": "vendor/underscore.string",
"main": "./lib/underscore.string"
}
],
"shim": {
"backbone": {
"deps": [
"jquery",
"lodash"
],
"exports": "Backbone"
}
}
};
}

if (typeof exports !== "undefined" && typeof module !== "undefined") {
module.exports = jam;
}
```