Skip to content

Instantly share code, notes, and snippets.

@scttnlsn
Created January 31, 2013 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scttnlsn/4684807 to your computer and use it in GitHub Desktop.
Save scttnlsn/4684807 to your computer and use it in GitHub Desktop.
RequireJS plugin to conditionally load modules based on environment
// 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