![](/img/trans.png)
[英]Component is not injecting in index.html file using grunt-wiredep
[英]Using gulp and wiredep, socket.io is not added to index.html (even though it is in bower.json)
我的bower.json文件中有angular,angular-ui-router和socket-io。
當我運行我的gulp文件(使用wiredep)時,兩個角度腳本成功添加到我的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 -->
//package.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
文件中排除了可選的main屬性,我相信,wiredep用它來編譯源文件數組。 檢查bower.json
的內部文件bower_components/socket.io/
文件夾,看看他們是否已經包括了這一點。 如果沒有,也許你可以對socket.io做一個pull請求或者至少提出一個問題?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.