使用gulp和wiredep,socket.io不会添加到index.html中(即使它在bower.json中)
Using gulp and wiredep, socket.io is not added to index.html (even though it is in bower.json)
我的bower.json文件中有angular、angular ui路由器和socket io。
当我运行我的gulp文件(使用wiredep)时,这两个angular脚本成功地添加到了我的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"
}
//gullfile.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 -->
//软件包.json
"devDependencies": {
"gulp": "^3.8.11"
}
Socket.io本身不支持bower,请记住这是服务器,而不是客户端。
您可以通过将客户端脚本的serveClient
选项设置为true
,将其直接插入到您的index
中,方法是:
<script src="socket.io/socket.io.js"></script>
或者安装bower中引用的客户端脚本,但使用另一个名称:
bower install -save socket.io-client
如果此包没有main
属性,则必须在主bower.json
:中覆盖它
"overrides": {
"socket.io-client": {
"main": "socket.io.js"
}
}
这样,wiredep将自动将其注入index.html
。
有时供应商会在他们的bower.json
文件中排除可选的主属性,我相信wiredep会使用它来编译源文件数组。检查bower_components/socket.io/
文件夹中的bower.json
文件,查看它们是否包含该文件。如果没有,也许你可以向socket.io请求pull,或者至少提出一个问题?
相关文章:
- 如何将json数据显示为html
- 如何将JSON转换为HTML下拉菜单
- AngularJS加载JSON数据,然后从中解析/加载HTML
- 如何在html angular中显示嵌套的json元素
- 从JSON填充列表(而不是HTML)
- 在HTML页面上将URL解析为可读的json格式
- tu如何将id放在填充了json数据的html表td上
- 嵌套JSON到平面HTML表
- http请求使用html而不是json进行响应
- 如何在带有nunjucks和gullow数据的JSON数据中使用带有HTML的内容
- 使用Angular显示JSON中的HTML
- 如何使用jQuery来解析json并将其作为列表输出到HTML中
- 通过Azure存储以HTML形式获取JSON文件
- ngResource没有'从JSON文件解析HTML时不起作用
- JavaScript-HTML表单到JSON(空值)和格式
- 使用 HTML JSON 进行调试
- jQuery获取text/html/json与脚本
- 测试字符串是否以.html|.html|.json结尾
- HTML Json解析字符串
- 如何编写一个HTML JSON AJAX测试工具与美化,语法突出显示JSON结果