Javascript 使用gulp和wiredep,socket.io不会添加到index.html(即使它在bower.json中)

Javascript 使用gulp和wiredep,socket.io不会添加到index.html(即使它在bower.json中),javascript,html,socket.io,gulp,wiredep,Javascript,Html,Socket.io,Gulp,Wiredep,我的bower.json文件中有角度、角度ui路由器和套接字io 当我运行我的gulp文件(使用wiredep)时,两个Angle脚本成功地添加到index.html文件中,但socket.io脚本没有,我也不知道为什么。谢谢你的帮助 //命令行 [21:56:06] Using gulpfile ~/dev/projects/ecommerceVidChat/gulpfile.js [21:56:06] Starting 'default'... [21:56:06] Starting 'bo

我的bower.json文件中有角度、角度ui路由器和套接字io

当我运行我的gulp文件(使用wiredep)时,两个Angle脚本成功地添加到index.html文件中,但socket.io脚本没有,我也不知道为什么。谢谢你的帮助

//命令行

[21:56:06] Using gulpfile ~/dev/projects/ecommerceVidChat/gulpfile.js
[21:56:06] Starting 'default'...
[21:56:06] Starting 'bower-dependencies'...
[21:56:06] Finished 'bower-dependencies' after 6.24 ms
[21:56:06] Finished 'default' after 7.24 ms
//bower.json

  "dependencies": {
    "angular": "~1.3.13",
    "socket.io": "~1.3.4",
    "angular-ui-router": "~0.2.13"
  }
//gulpfile.js

var gulp = require('gulp'),
    wiredep = require('wiredep').stream;

gulp.task('default', function() {
  gulp.start('bower-dependencies')
});

gulp.task('bower-dependencies', function () {  
  gulp.src('./build/index.html') 
    .pipe(wiredep({
      directory: './build/bower_components',
      bowerJson: require('./bower.json'),
    }))
    .pipe(gulp.dest('./build/'));
});
//index.html

<!-- bower:js -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<!-- endbower -->

有时,供应商会在其
bower.json
文件中排除可选属性,我相信wiredep会使用该属性编译源文件数组。检查
bower\u components/socket.io/
文件夹中的
bower.json
文件,查看是否包含该文件。如果没有,也许您可以向socket.io发出pull请求,或者至少提出一个问题

Socket.io本身不支持bower,请记住,它是服务器,而不是客户端

通过将其
serveClient
选项设置为
true
,并直接将其插入到
索引中,您可以使用套接字服务器为客户端脚本提供服务:

 <script src="socket.io/socket.io.js"></script>
如果此包没有
main
属性,则必须在main
bower.json中重写它:

"overrides": {
  "socket.io-client": {
    "main": "socket.io.js"
  }
}

通过这种方式,wiredep将自动将其注入您的
index.html

在使用yeoman和编辑bower.json文件时,main的值为
dist/socket.io.js
。解决方案:
“main”:“dist/socket.io.js”
实际上可以正确使用wiredep
bower install -save socket.io-client
"overrides": {
  "socket.io-client": {
    "main": "socket.io.js"
  }
}