简体   繁体   中英

Grunt run shell after 'watch' eventListener changes filename

I'm trying to run shell command when file changes. Getting last changed file to use as argument for shell command. Here is the code:

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 actually works, but it does after shell command runs. How can I run task before event has been triggered?

options: { nospawn: true } for the watch task helped me on this.

Thanks guys from this thread: How to modify grunt watch tasks based on the file changed?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM