Grunt.js永远守望 [英] Grunt.js Watch Forever

查看:126
本文介绍了Grunt.js永远守望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:



我试图在 Gruntfile中运行 watch 任务.js 作为守护进程。



通常情况下,我会执行如下脚本: grunt watch



Gruntfile.js:



  module.exports =函数(grunt){

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

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



问题:



作为一个守护进程产生 grunt watch 更新:

看起来好像已经做了一些考虑:

https://github.com/shama/grunt-hub#watching-forever

https://github.com/shama/grunt-hub/issues/3 p>

解决方案

您可以使用 https ://github.com/nodejitsu/forever exmaple

  forever start gruntstart.js 

code>

gruntstart.js:

  var exec = require('child_process')。exec; 
$ b $ 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);
}
});


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

解决方案

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);
        }
});

这篇关于Grunt.js永远守望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆