[英]Running a grunt task on one Gruntfile from another
我的項目根目錄中有一個Gruntfile。 我還在app / components / jquery目錄中通過Bower安裝了jQuery。
作為我的Gruntfile的一部分,我想在jQuery Gruntfile上運行一些命令來構建庫的自定義版本。
我如何從我的Gruntfile中獲取?
您可以創建一個簡單的任務,在您想要的文件夾中生成咕嚕聲 :
grunt.registerTask('run-grunt', function () {
var done = this.async();
grunt.util.spawn({
grunt: true,
args: [''],
opts: {
cwd: 'app/components/jquery'
}
}, function (err, result, code) {
done();
});
});
如果你想獲得控制台輸出,建立@Sindre的答案,你所要做的就是控制台記錄result.stdout。
grunt.registerTask('run-grunt', function() {
var cb = this.async();
grunt.util.spawn({
grunt: true,
args: ['clean', 'copy:fonts'],
opts: {
cwd: 'bower_components/bootstrap'
}
}, function(error, result, code) {
console.log(result.stdout);
cb();
});
});
根據@Sindre和@ Stephen的回答,我們還可以“實時”獲取控制台輸出而不進行緩沖:
grunt.registerTask('run-grunt', function() {
var cb = this.async();
var child = grunt.util.spawn({
grunt: true,
args: ['clean', 'copy:fonts'],
opts: {
cwd: 'bower_components/bootstrap'
}
}, function(error, result, code) {
cb();
});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
});
不知道這是否有效,但你可以嘗試一下。 你的jQuery Gruntfile是通過“module.exports”導出的。 這應該意味着,您可以在代碼中使用它並使用它。
var jQueryGrunt = require('path-to-jquery-gruntfile');
jQueryGrunt.task.run(['your-task-you-want-to-run']);
聽聽這是否有效將會很有趣......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.