有没有一种方法可以根据更改的文件动态指定要运行的任务?
换句话说:
watch: {
exec: {
files: [html/*.html],
tasks: ['exec:my_exec_task:THE_FILE_THAT_CHANGED']
}
}我可以捕获手表事件,但我不能从回调中运行任务,因为它“做错了”。
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 */
}
});至少文档是这么说的:https://github.com/gruntjs/grunt-contrib-watch#using-the-watch-event
有什么想法吗?
发布于 2015-03-25 21:23:28
根据文档
监视事件并不是用来替代标准的Grunt API来配置和运行任务的。如果您试图从watch事件中运行任务,那么您很可能做错了。请阅读配置任务。
您不能从事件运行任务,但可以在任务开始前更改配置。添加到监视配置选项部分spawn: false
grunt.initConfig({
watch: {
scripts: {
files: ['app/*.js'],
tasks: ['jshint:one'],
options: {
spawn: false,
},
},
},
jshint: {
one: {src: ""},
},
});并在监视事件时“即时”更改配置
grunt.event.on('watch', function(action, filepath) {
grunt.config('jshint.one.src', filepath);
});在应用配置之后,watch部分将运行任务jahint:one。
https://stackoverflow.com/questions/23274324
复制相似问题