Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Doing multiple almond builds with a nodejs script, example
//Download jquery.js and place it in the build, do not use require-jquery.js
//in the build, since each of the build layers just needs almond and not the
//full require.js file.
//This file is run in nodejs to do the build: node build.js
//Load the requirejs optimizer
var requirejs = require('./r.js');
//Set up basic config, include config that is
//common to all the requirejs.optimize() calls.
var baseConfig = {
baseUrl: "some/path",
locale: "en-us",
// optimize: "uglify",
optimize: "none", // For debugging built versions
wrap: true,
paths: {
//Remember, use downloaded jQuery 1.7 or greater,
//not require-jquery.js
'jquery': 'libs/jquery/jquery',
'underscore': 'libs/underscore/underscore',
'backbone': 'libs/backbone/backbone',
'templates': '../oerglue_templates'
//All the built layers will use almond.
name: 'almond'
//Create an array of build configs, the baseConfig will
//be mixed in to each one of these below. Since each one needs to
//stand on their own, they all include jquery and the noConflict.js file
var configs = [
include: ['jquery', 'noConflict', 'main'],
out: '../oerglue_js_min/main.js'
include: ['jquery', 'noConflict', 'main-frame'],
out: '../oerglue_js_min/main-frame.js'
include: ['jquery', 'noConflict', 'main-mods'],
out: '../oerglue_js_min/main-mods.js'
include: ['jquery', 'noConflict', 'main-edit'],
out: '../oerglue_js_min/main-edit.js'
// Function used to mix in baseConfig to a new config target
function mix(target) {
for (var prop in baseConfig) {
if (baseConfig.hasOwnProperty(prop)) {
target[prop] = baseConfig[prop];
return target;
//Create a runner that will run a separate build for each item
//in the configs array. Thanks to @jwhitley for this cleverness
var runner = configs.reduceRight(function(prev, currentConfig) {
return function (buildReportText) {
requirejs.optimize(mix(currentConfig), prev);
}, function(buildReportText) {
//Run the builds

jrburke commented Dec 22, 2011

This is based on this gist, and part of this requirejs thread.

jbasdf commented Dec 22, 2011

I had to add baseUrl to basConfig or node would complain:
baseUrl: "public/oerglue_js",

Then I changed the paths to match my system and it works great!


jrburke commented Dec 22, 2011

Thanks for the catch, i added baseUrl to the gist and also console.log() for the build output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment