2016-02-11 53 views
1

我一直試圖讓wiredep一飲而盡產生我的腳本標記和路徑加載腳本(和--save-DEV)通過鮑爾,如顯示在無數的教程中,但無論我做什麼,它都會複製html源文件,但不會注入腳本標記和路徑。Wiredep +咕嘟咕嘟不會產生任何腳本標記和路徑

我現在只想連接Bower.json文件,所以我已經刪除了處理css文件的示例腳本部分,這些腳本包含在大多數示例中。

gulpfile.js:(摘要只)

gulp.task('bower', function() { 
    var wiredep = require('wiredep').stream; 
    return gulp.src('./src/index.html') 
     .pipe(wiredep({ 
          cwd  : './src', 
          directory: './bower_components/', 
          bowerJson: require('./bower.json'), 
         })) 
     .pipe(gulp.dest('./build')); 
}); 

bower.json文件

{ 
    "name": "SomeProject", 
    "description": "", 
    "ignore": [ 
    "**/.*", 
    "node_modules", 
    "bower_components", 
    "test", 
    "tests" 
    ], 
    "devDependencies": { 
    "angular-mocks": "~1.4.9", 
    "angular": "~1.4.9", 
    "jquery": "components/jquery#^2.2.0", 
    "angular-aria": "^1.5.0" 
    } 
} 

.bowerrc文件

{ 
    "directory" : "bower_components" 
} 

index.html文件的最後幾行

</div> 
</div> 

<!--bower:js--> 
<!--endbower--> 
<script src="js/app.js" type = "text/javascript"></script> 
</body> 
</html> 

所以,我運行它,並將其複製index.html文件到正確的位置,但在HTML文件的輸出是完全一樣的輸入。

結果:

</div> 
</div> 

<!--bower:js--> 
<!--endbower--> 
<script src="js/app.js" type = "text/javascript"></script> 
</body> 
</html> 

我缺少什麼?

的事情,我已經試過了沒有什麼區別:

  • 添加或刪除從空間和
  • 在gulpfile.js的頭部和gulp.task內需要wiredep
  • 調用帶或不帶選項的wiredep
  • 嘗試不同的選項和不同的路徑
  • 將變量用於源和目標的inlineglobs
  • 使用後斜線或不
  • 使用./或不
  • 用空.bowerrc文件與一個如以上
  • 重命名吞任務
  • 卸下從「忽略」節bower.json文件與否
+0

你一口任務需要返回流。 'return gulp.src(...)' –

+0

剛剛添加它,但在輸出中沒有任何區別。仍然沒有收穫。 – MaxRocket

+0

在任務外聲明'var wiredep = require()。stream'?另外,你認爲這是因爲你的bower.json文件忽略了bower_components? –

回答

2

主要問題出在您的bower.json文件中。將devDependencies更改爲dependencies,因爲這是wiredep預期的值。它沒有找到它想要的東西。 :

涼亭。JSON

{ 
    "name": "SomeProject", 
    "description": "", 
    "ignore": [ 
    "**/.*", 
    "node_modules", 
    "bower_components", 
    "test", 
    "tests" 
    ], 
    "dependencies": { 
    "angular-mocks": "~1.4.9", 
    "angular": "~1.4.9", 
    "jquery": "components/jquery#^2.2.0", 
    "angular-aria": "^1.5.0" 
    } 
} 

此外,您gulpfile的wiredep並不需要任何參數

gulpfile.js

gulp.task('bower', function() { 
    var wiredep = require('wiredep').stream; 
    return gulp.src('./src/index.html') 
    pipe(wiredep({ 
     // cwd  : './src',  // <--------------- TAKE THIS LINE OUT 
     // directory: './bower_components/', /// <--- AND REMOVE ALL THESE 
     // bowerJson: require('./bower.json') /// <--- (UNLESS YOUR GULPFILE IS IN ANOTHER DIRECTORY) 
     // onError : function(err) {  /// <--- I used these for debugging. Uncomment them and you'll see things be more verbose when you call this gulp task. 
     //  console.log("Wiredep error: "+err); 
     // }, 
     // onFileUpdated : function (filePath) { 
     //  console.log('File path was updated: ' + filePath); 
     // }, 
     // onPathInjected : function (fileObject) { 
     //  console.log('Path injected: ' + JSON.stringify(fileObject)); 
     // } 
    })) 
    .pipe(gulp.dest('./build')); 
}); 
+0

太棒了。謝謝!我無法弄清楚我的生活。 – MaxRocket