我已向此registerTask
Gruntfile.js
次调用
grunt.task.registerTask('runDebug', 'Run the app with debug flag', function() {
var done = this.async();
grunt.util.spawn({
cmd: 'node',
args: ['--debug', './node_modules/nodemon/nodemon.js', 'index.js'],
opts: {
stdio: 'inherit'
}
}, function (error, result, code) {
if (error) {
grunt.log.write (result);
grunt.fail.fatal(error);
}
done();
});
grunt.log.writeln ('node started');
grunt.util.spawn({
cmd: 'node-inspector',
args: ['&'],
opts: {
//cwd: current working directory
}
},
function (error, result, code) {
if (error) {
grunt.log.write (result);
grunt.fail.fatal(error);
}
done();
});
grunt.log.writeln ('inspector started');
});
grunt.task.registerTask('debug', ['runDebug', 'compile', 'watch']);
新的debug
任务类似于现有的server
任务。但是,grunt server
命令运行compile
,watch
和runNode
任务,而grunt debug
命令仅运行runDebug
任务。
我在这里缺少什么?为什么compile
和watch
任务不能与grunt debug
命令一起运行。
答案 0 :(得分:0)
您的代码多次调用done()
返回的this.async()
函数。这可能会让Grunt感到困惑。我建议您调用自己的函数,该函数可以命名为spawned()
,而不是直接在回调函数中调用done()
。该功能可能类似于:
var expected_spawns = 2;
function spawned() {
if (!--expected_spawns)
done();
if (expected_spawns < 0)
throw new Error("too many spawns!") // Or some of Grunt's fail functions.
}
这种方式done()
将被调用一次。