Skip to content

Instantly share code, notes, and snippets.

@webuniverseio
Created December 6, 2012 19:23
Show Gist options
  • Save webuniverseio/4227481 to your computer and use it in GitHub Desktop.
Save webuniverseio/4227481 to your computer and use it in GitHub Desktop.
requirejs build config - common module exclude
/*global require:true, console: true*/
var requirejs = require('requirejs'),
//...
config = {
//...
modules: [
{
name: 'app/core',
include: ['app/modules/app-flow', 'app/modules/font-resize']
},
{
name: 'app/modules/app-flow',
exclude: ['app/helper']
}
//,..
]
};
var globalExcludeModules = ['app/sandbox!'],
modules = config.modules,
modulesCount = modules.length,
module;
if (globalExcludeModules.length) {
while (modulesCount--) {
module = modules[modulesCount];
if (module.name !== 'app/core') {
switch (typeof module.exclude) {
case 'undefined':
module.exclude = globalExcludeModules;
break;
case 'object':
module.exclude = module.exclude.concat(globalExcludeModules);
break;
default:
break;
}
}
}
}
requirejs.optimize(config, function logOptimizerOutput(output) {
'use strict';
console.log(output);
//output is just a text output of the modules
//included. Load the built file for the contents.
//Use config.out to get the optimized file contents.
//var contents = fs.readFileSync(config.dir+'build.txt', 'utf8');
}, function logOptimizerError(error) {
'use strict';
console.log(error.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment