无意中看到一段代码,感觉挺有意思的,就是把外部非AMD、CommonJS的模块封装成这两个模块。
(function (factory) {
/* jshint ignore:start */
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
/* jshint ignore:end */
}(function($) {...}));