我正在尝试在我的应用程序中使用inview插件,它使用RequireJS加载脚本,并正在使用Almond构建/优化。我得到一个控制台错误:
TypeError: 'undefined' is not an object (evaluating 'global.jquery.inview')它似乎来自需要添加到inview文件末尾的shim:
define("jquery.inview", ["jquery"], (function (global) {
return function () {
var ret, fn;
return ret || global.jquery.inview;
};
}(this)));我的需要配置如下:
require.config({
paths: {
'jquery': '../../bower_components/jquery/dist/jquery',
'text': '../../bower_components/requirejs-text/text',
'tweenmax': '../../bower_components/greensock/src/uncompressed/TweenMax',
'jquery.inview': '../../bower_components/jquery.inview/jquery.inview'
},
shim: {
"jquery.inview": {
deps: ['jquery'],
exports: 'jquery.inview'
}
}
});任何帮助都非常感谢!
发布于 2014-08-27 10:36:46
jquery.inview是一个jQuery插件。因此,它会像插件一样,通过修改$来安装自己。当您告诉RequireJS它导出jquery.inview时,RequireJS试图解决全局空间中的jquery.inview问题,这是因为jQuery可以作为$或jQuery在全局空间中访问,而不是以jquery的形式访问。
您可以不使用exports,也可以将其设置为jquery.inview确实定义的内容。例如,阅读jquery.inview的代码,我看到它设置了$.event.special.inview,这样您就可以在exports中使用它。
如果您想知道,对于jQuery插件,exports值只对RequireJS的簿记有用。您并不是通过插件导出的值来访问插件,而是通过它通过jQuery公开的API访问插件。
https://stackoverflow.com/questions/25524587
复制相似问题