Grunt.js Watch Forever

徘徊边缘 提交于 2019-12-10 16:15:20

问题


Goal:

I am trying to run a watch task in my Gruntfile.js as a daemon.

Normally, I would execute this script like: grunt watch.

Gruntfile.js:

module.exports = function(grunt) {

  grunt.initConfig({
    concat: {
      options: {
        separator: ''
      },
      dist: {
        src: ['static/js/**/*.js'],
        dest: 'app.js'
      }
    },
    watch: {
      files: ['<%= concat.dist.src %>'],
      tasks: ['concat']
    }
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-concat');
};

Question:

How do I spawn grunt watch as a daemon?

Update:

It appears as though considerations for this have already been made:
https://github.com/shama/grunt-hub#watching-forever
https://github.com/shama/grunt-hub/issues/3


回答1:


you can use https://github.com/nodejitsu/forever exmaple

forever start gruntstart.js

gruntstart.js:

var exec = require('child_process').exec;

exec('grunt watch > log/grunt.log',
    function (error, stdout, stderr) {
        console.log('stdout: ' + stdout);
        console.log('stderr: ' + stderr);
        if (error !== null) {
           console.log('exec error: ' + error);
        }
});



回答2:


I'm a newbie in javascript, but I solved this problem with: tmux

  1. One pane for simple operations like git and etc.
  2. Other is for "grunt watch"

Even if I close the console tmux will go on with watching :D
http://i.imgur.com/9L04OGe.jpg



来源:https://stackoverflow.com/questions/15622116/grunt-js-watch-forever

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!