Created
December 1, 2011 19:07
-
-
Save jrburke/1419063 to your computer and use it in GitHub Desktop.
Multiple single file builds using one "build script" for requirejs optimizer
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
//Load the requirejs optimizer | |
var requirejs = require('./path/to/r.js'), | |
//Set up basic config, include config that is | |
//common to all the optimize() calls. | |
basConfig = { | |
baseUrl: './some/path', | |
paths: { | |
//whatever is neded globally. | |
} | |
}; | |
// 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; | |
} | |
//Now do a series of builds of individual files, using the args suggested by: | |
//http://requirejs.org/docs/optimization.html#onejs | |
requirejs.optimize(mix({ | |
name: 'first/main/module', | |
include: [/*if you need to include extra modules */], | |
out: 'path/to/output/firstMain-built.js' | |
}), function (buildReportText) { | |
//First build complete, start the next one. | |
requirejs.optimize(mix({ | |
name: 'second/main/module', | |
include: [/*if you need to include extra modules */], | |
out: 'path/to/output/secondMain-built.js' | |
}), function (buildReportText) { | |
//all done. | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@whitley, neat use of reduceRight, thanks for the explanation. Nice approach to know in general for repeated async calls.