Gruntjs 使用grunt contrib watch运行动态命名的grunt任务
是否有方法根据更改的文件动态指定要运行的任务 换言之:Gruntjs 使用grunt contrib watch运行动态命名的grunt任务,gruntjs,grunt-contrib-watch,Gruntjs,Grunt Contrib Watch,是否有方法根据更改的文件动态指定要运行的任务 换言之: watch: { exec: { files: [html/*.html], tasks: ['exec:my_exec_task:THE_FILE_THAT_CHANGED'] } } 我可以捕获watch事件,但是我不能在回调中运行任务,因为它做错了 grunt.event.on('watch', function(action, filepath, target) { if (target === 'ex
watch: {
exec: {
files: [html/*.html],
tasks: ['exec:my_exec_task:THE_FILE_THAT_CHANGED']
}
}
我可以捕获watch事件,但是我不能在回调中运行任务,因为它做错了
grunt.event.on('watch', function(action, filepath, target) {
if (target === 'exec') {
grunt.task.run('exec:my_exec_task:' + filepath); /* this doesn't work */
grunt.config('filepath', filepath); /* and neither does this, it's undefined in my exec task */
}
});
至少文件上是这么说的:
有什么想法吗?根据文档
监视事件不用于替换用于配置和运行任务的标准Grunt API。如果您试图在watch事件中运行任务,那么很可能是做错了。请阅读配置任务
不能从事件运行任务,但可以在任务开始之前更改配置。添加到监视配置选项部分生成:false
和实时事件更改配置
grunt.event.on('watch', function(action, filepath) {
grunt.config('jshint.one.src', filepath);
});
应用配置后,监视部分将运行任务jahint:one
grunt.event.on('watch', function(action, filepath) {
grunt.config('jshint.one.src', filepath);
});