我正在尝试将我的Node应用程序作为Grunt任务运行.但是,我需要将其作为子进程生成,以允许我并行运行监视任务.
这有效:
grunt.registerTask('start', function () {
grunt.util.spawn(
{ cmd: 'node'
, args: ['app.js']
})
grunt.task.run('watch:app')
})
Run Code Online (Sandbox Code Playgroud)
但是,当监视任务检测到更改时,这将再次触发启动任务.在我生成我的Node应用程序的另一个子进程之前,我需要杀死前一个.
但是,我无法弄清楚如何杀死这个过程.这样的东西不起作用:
var child
grunt.registerTask('start', function () {
if (child) child.kill()
child = grunt.util.spawn(
{ cmd: 'node'
, args: ['app.js']
})
grunt.task.run('watch:app')
})
Run Code Online (Sandbox Code Playgroud)
看起来:
undefined.child没有kill功能......