seajs - 怎么把2.0版本之前的jquery包装成支持cmd和amd规范的插件库?
本文介绍了seajs - 怎么把2.0版本之前的jquery包装成支持cmd和amd规范的插件库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
1.本人页面引用的是:jquery1.8.3
2.页面的代码组织工具用了seajs
页面报错:
请问:
不支持cmd和amd扩展的jquery代码怎么改造成支持这两种规范的模块?
参考资料:
/*
* http://julabs.com
*/
(function(factory) {
if (typeof define === 'function') {
define('/jquery', [], factory);
}
else {
factory();
}
})(function(require) {
//这里放jQuery源代码
if (require) return $.noConflict(true);
});
上面这种方式试过了没有效果?
来源:http://julabs.com/blog/seajs-...
解决方案
使用umd模块写法
https://github.com/umdjs/umd/...
// if the module has no dependencies, the above pattern can be simplified to
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.returnExports = factory();
}
}(this, function () {
// Just return a value to define the module export.
// This example returns an object, but the module
// can return a function as the exported value.
// 这里放jq源码
return window.jQuery;
}));
这篇关于seajs - 怎么把2.0版本之前的jquery包装成支持cmd和amd规范的插件库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文