Grunt - 同时执行和监视应用程序
Grunt - Execute and Watch application at same time
我在开发一个简单的节点应用程序时遇到了这个名为 g运行t-cli 的工具。
在介绍 g运行t 之后,我打算在我的应用程序中使用它。
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'));
});
运行先执行再监视是否正确?不知何故我觉得终端只卡在执行任务上,它没有观察应用程序的变化。
你的 g运行t execute 目标正在阻塞 watch 并且永远不会结束。这两个任务需要 运行 在不同的线程中。
您可以使用类似 g运行t-concurrent 的东西来同时执行这两个任务:
https://github.com/sindresorhus/grunt-concurrent
我在开发一个简单的节点应用程序时遇到了这个名为 g运行t-cli 的工具。
在介绍 g运行t 之后,我打算在我的应用程序中使用它。
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'));
});
运行先执行再监视是否正确?不知何故我觉得终端只卡在执行任务上,它没有观察应用程序的变化。
你的 g运行t execute 目标正在阻塞 watch 并且永远不会结束。这两个任务需要 运行 在不同的线程中。
您可以使用类似 g运行t-concurrent 的东西来同时执行这两个任务: https://github.com/sindresorhus/grunt-concurrent