Grunt – 同时执行和观看应用程序

我正在开发一个简单的节点应用程序,我碰到了这个叫做grunt-cli的工具。

在介绍到咕噜之后,我打算把它和我的应用程序一起使用。

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

运行execute和watch后是否正确? 不知何故,我觉得terminal卡在执行任务只是,它不看在应用程序的变化。

你的咕execute执行的目标是阻止观看,永远不会结束。 这两个任务需要在不同的线程中运行。

你可以使用类似grunt-concurrent的东西同时执行这两个任务: https : //github.com/sindresorhus/grunt-concurrent