Gruntjs Grunt在'之后运行shell;手表';eventListener更改文件名

Gruntjs Grunt在'之后运行shell;手表';eventListener更改文件名,gruntjs,grunt-contrib-watch,Gruntjs,Grunt Contrib Watch,我正在尝试在文件更改时运行shell命令。正在获取上次更改的文件以用作shell命令的参数。代码如下: grunt.initConfig({ changedFile: 'test', watch: { all: { files: ['js/*.js'], tasks: ['shell'] } }, shell: { run: { // it

我正在尝试在文件更改时运行shell命令。正在获取上次更改的文件以用作shell命令的参数。代码如下:

grunt.initConfig({
    changedFile: 'test',

    watch: {
        all: {
            files: ['js/*.js'],
            tasks: ['shell']
        }
    },

    shell: {
        run: {
            // it outputs 'test', not changed file
            command: 'touch <%= changedFile %>'
        }
    }

});

grunt.event.on('watch', function(action, filepath) {
    grunt.config('changedFile', filepath);
});
grunt.initConfig({
更改文件:“测试”,
观察:{
全部:{
文件:['js/*.js'],
任务:['shell']
}
},
外壳:{
运行:{
//它输出“测试”,未更改文件
命令:“触摸”
}
}
});
grunt.event.on('watch',函数(操作,文件路径){
grunt.config('changedFile',filepath);
});

“watch”eventListener实际上可以工作,但它在shell命令运行后可以工作。如何在事件触发之前运行任务?

选项:{nospawn:true}
对于
监视
任务,我在这方面有所帮助

感谢来自本帖的朋友们: