【问题标题】:Grunt run shell after 'watch' eventListener changes filename'watch' eventListener 更改文件名后 Grunt 运行 shell
【发布时间】:2014-11-05 14:44:04
【问题描述】:

我正在尝试在文件更改时运行 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);
});

'watch' eventListener 确实有效,但它在 shell 命令运行后才有效。如何在事件触发之前运行任务?

【问题讨论】:

    标签: gruntjs grunt-contrib-watch


    【解决方案1】:

    options: { nospawn: true }watch 任务帮助了我。

    感谢这个帖子的人:How to modify grunt watch tasks based on the file changed?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多