2016-09-09 16 views
1

我正在開發一個簡單的節點應用程序,並且遇到這個名爲grunt-cli的工具。Grunt - 同時執行和監視應用程序

在介紹到咕嚕聲之後,我計劃將它與我的應用程序一起使用。

Gruntfile.js

module.exports = function(grunt){ 

    grunt.initConfig({ 
     execute: { 
      target:{ 
       src: ['app.js'] 
      } 
     }, 
     watch: { 
      scrpits: { 
       files: ['app.js'], 
       tasks: ['execute'], 
       options: { 
        spawn: false 
       } 
      } 
     } 
    }); 

    grunt.loadNpmTasks('grunt-execute'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 

    grunt.registerTask('default', ['execute', 'watch']); 
}; 

的package.json

{ 
    "name": "exampleapp", 
    "version": "1.0.0", 
    "description": "", 
    "main": "app.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "Priyank Thakkar", 
    "license": "ISC", 
    "dependencies": { 
    "express": "^4.14.0", 
    "grunt": "^0.4.1" 
    }, 
    "devDependencies": { 
    "grunt-contrib-watch": "^1.0.0", 
    "grunt-execute": "^0.2.2" 
    } 
} 

app.js

var express = require('express'); 

var app = express(); 

app.set('port', process.env.port || 3005); 

app.listen(3005, function(){ 
    console.log('application started at http://localhost:' + app.get('port')); 
}); 

是否正確運行EXECUT隨後看手錶?不知何故,我覺得終端只停留在執行任務上,它並沒有注意到應用程序的變化。

回答

1

你的咕execute執行目標是阻止觀看,永不結束。這兩個任務需要在不同的線程中運行。

您可以使用類似咕嚕併發同時執行這兩個任務: https://github.com/sindresorhus/grunt-concurrent

+0

我同意你的建議達成一致。這是兩項阻塞任務。所以我不得不通過grunt-concurrent來運行它們。謝謝, –