Skip to content

Instantly share code, notes, and snippets.

@jwhitley
Created December 16, 2011 21:18
Show Gist options
  • Save jwhitley/1488036 to your computer and use it in GitHub Desktop.
Save jwhitley/1488036 to your computer and use it in GitHub Desktop.
//Load the requirejs optimizer
var requirejs = require('/Users/whitley/src/requirejs-rails/bin/r.js'),
//Set up basic config, include config that is
//common to all the optimize() calls.
basConfig = {
"baseUrl": "/Users/whitley/src/foo/tmp/assets",
"modules": [
{
"name": "application"
},
{
"name": "hello"
}
]
};
// Function used to mix in baseConfig to a new config target
function mix(target) {
for (var prop in basConfig) {
if (basConfig.hasOwnProperty(prop)) {
target[prop] = basConfig[prop];
}
}
return target;
}
var module_specs = [
{
name: "application",
out: '/Users/whitley/src/foo/public/assets/application.js'
},
{
name: "hello",
out: '/Users/whitley/src/foo/public/assets/hello.js'
},
];
// Do a series of builds of individual files, using the args suggested by:
// http://requirejs.org/docs/optimization.html#onejs
//
// r.js will eventually need a nested call idiom to handle async
// builds. Anticipating that need.
var async_runner = module_specs.reduceRight(function(prev, curr) {
return function (buildReportText) {
requirejs.optimize(mix(curr), prev);
};
}, function(buildReportText) {} );
async_runner();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment