Created
January 31, 2013 17:55
-
-
Save scttnlsn/4684807 to your computer and use it in GitHub Desktop.
RequireJS plugin to conditionally load modules based on environment
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
// Include { env: 'development' } in your RequireJS config | |
// When building (with r.js) set the value to 'production' or just omit it entirely | |
// | |
// Assuming the following directory structure: | |
// - config/ | |
// - development.js | |
// - production.js | |
// | |
// Load the appropriate file based on the current env: | |
// | |
// var config = require('env!config'); | |
define(function() { | |
return { | |
load: function(name, req, load, config) { | |
if (!config.env || config.isBuild) { | |
config.env = 'production'; | |
} | |
var path = name + '/' + config.env; | |
req([path], function(mod) { | |
load(mod); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment