Created
December 22, 2011 05:58
-
-
Save jrburke/1509135 to your computer and use it in GitHub Desktop.
Doing multiple almond builds with a nodejs script, example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) { | |
console.log(buildReportText); | |
requirejs.optimize(mix(currentConfig), prev); | |
}; | |
}, function(buildReportText) { | |
console.log(buildReportText); | |
}); | |
//Run the builds | |
runner(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.noConflict(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the catch, i added baseUrl to the gist and also console.log() for the build output