Nodemon-like task in Grunt : execute node process and watch

前端 未结 3 1423
执笔经年
执笔经年 2021-02-03 22:49

I feel like I\'m missing something.

Here is what I want to achieve :

Having a grunt task that executes my server.js and runs watch task

3条回答
  •  醉话见心
    2021-02-03 23:15

    Use grunt-concurrent

    The issue is that tasks like watch and nodemon will never terminate, so grunt will never reach them. You need to spawn a new process.

    You can do this easily using grunt-concurrent:

    https://github.com/sindresorhus/grunt-concurrent

    For example:

    module.exports = function(grunt) {
      grunt.initConfig({
    
        ...
    
        concurrent: {
          dev: {
            tasks: ['nodemon', 'watch'],
            options: {
              logConcurrentOutput: true
            }
          }
        }
      });
    };
    

    The two will now run happily side by side.

提交回复
热议问题