lodash: Add support for more AMD build optimizers and allow aliasing as the "underscore" module. [jddalton]

Former-commit-id: 6b3fa45d19f6a55aa7565bcb4d9221f6f159e9c9
This commit is contained in:
John-David Dalton
2012-04-24 18:15:47 -04:00
parent bb09d77eb5
commit f9358531ad
5 changed files with 37 additions and 28 deletions

View File

@@ -2796,23 +2796,20 @@
else {
freeExports._ = lodash;
}
} else {
// in a browser or Rhino
}
// in a browser or Rhino
else {
// Expose Lo-Dash to the global object even when an AMD loader is present in
// case Lo-Dash was injected by a third-party script and not intended to be
// loaded as a module. The global assignment can be reverted in the Lo-Dash
// module via its `noConflict()` method.
window._ = lodash;
// Expose Lo-Dash as an AMD module, but only for AMD loaders that understand
// the issues with loading multiple versions of Lo-Dash in a page that all
// might call `define()`. The loader will indicate they have special
// allowances for multiple Lo-Dash versions by specifying
// `define.amd.lodash=true`. Register as a named module, since Lo-Dash can
// be concatenated with other files that may use `define()`, but not use a
// proper concatenation script that understands anonymous AMD modules.
// Lowercase `lodash` is used because AMD module names are derived from
// file names, and Lo-Dash is normally delivered in a lowercase file name.
// Do this after assigning Lo-Dash the global so that if an AMD module wants
// to call `noConflict()` to hide this version of Lo-Dash, it will work.
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd && define.amd.lodash) {
define('lodash', function() {
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
// define as an anonymous module so, through path mapping, it can be
// referenced as the "underscore" module
define(function() {
return lodash;
});
}