3
我有一個Yeoman webapp
項目,我已經使用bower
添加了socket.io-client
。當運行grunt構建時socket.io客戶端中斷
當我運行webapp grunt server
時,一切正常。但是,當我與grunt build
建立它,我得到以下錯誤:
Uncaught TypeError: Cannot call method 'push' of undefined
通過Gruntfile.js
(generateSourceMaps: true
),使源地圖,我設法追查錯誤的socket.io.js
來源:
/**
* Add the transport to your public io.transports array.
*
* @api private
*/
io.transports.push('websocket');
什麼可以使io.transports
成爲undefined運行後grunt build
?
UPDATE:
也許值得一說的是我用RequireJS和它的配置是這樣的:
require.config({
paths: {
jquery: '../bower_components/jquery/jquery',
// ...
// socket.io: Try the node server first
'socket.io': ['/socket.io/socket.io', '../bower_components/socket.io-client/dist/socket.io'],
},
shim: {
// Export io object: https://gist.github.com/guerrerocarlos/3651490
'socket.io': {
exports: 'io'
}
}
});
require(['jquery', 'socket.io'], function ($, io) {
'use strict';
// ...
});