我是require.js的新手,嘗試在我的頁面上使用RosLib.js加載require.js。 RosLib.js依賴於EventEmitter2。require.js Shim配置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?
你有拼寫錯誤:'rislib' - 'roslib' –
謝謝!糾正它,但仍然有錯誤 – SailAvid