我是 require.js 的新手,并尝试通过使用require.js加载它来在我的页面上使用 RosLib.js。RosLib.js 依赖于EventEmitter2。
所以这是我的代码:
require.config({
shim: {
eventemitter: {
exports: 'EventEmitter2'
},
roslib: {
deps: ["eventemitter"],
exports: "ROSLIB"
}
},
paths: {
roslib: "https://raw.github.com/RobotWebTools/roslibjs/devel/build/roslib",
eventemitter: "https://raw.github.com/hij1nx/EventEmitter2/master/lib/eventemitter2"
}
});
require(["roslib"], function (ROSLIB) {
var urlname = "ws://" + location.hostname + ":9090";
ros = new ROSLIB.Ros({
url : urlname
});
});
如果函数被执行 somhow eventemitter2.js 有错误并且EventEmitter2
未定义:
Uncaught ReferenceError: module is not defined (eventemitter2.js:561)
Uncaught ReferenceError: EventEmitter2 is not defined (roslib.js:121)
这是相应的示例 JsFiddle 不起作用:http: //jsfiddle.net/mKyEA/1/
如何配置 require.js 才能正确初始化 EventEmitter2?