我想在我的插件中使用fs.watch
。但是在运行任务和文件监视被停止后,grunt进程将退出。如何保持文件监视任务正常工作?我在grunt-contrib-watch
grunt.registerTask('prevent', 'watch file and prevent process exit', function(grunt){ _fs = require('fs') _fs.watch(process.cwd(), function(event, filename){ console.log(event, filename) } }
感谢您的投入!
答案 0 :(得分:1)
如果您希望Grunt等待,您可以在任务函数中调用this.async
:
grunt.registerTask('prevent', 'watch file and prevent process exit',
function (grunt) {
var done = this.async(),
_fs = require('fs');
_fs.watch(process.cwd(), function (event, filename) {
console.log(event, filename)
});
});
请参阅this.async
doc here。