我想在我的插件中使用 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) } }
感谢您的输入!
最佳答案
如果你想让 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
文档 here .
关于javascript - 如何防止 grunt 进程退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25378682/