使用grunt运行两个异步任务 [英] Running 2 async tasks with grunt
问题描述
我正在开发一个小节点项目,我使用coffeescript和更少的客户端代码。我试图使用grunt设置我的开发环境。我已经实现自定义grunt任务运行服务器像这样:
I am working on a small node project and I use coffeescript and less for client-side code. I am trying to set up my development environment using grunt. I've implemented custom grunt task for running server like this:
start = require './start' #just a function to start express.js application
grunt.registerTask 'server', 'Starting server', ->
grunt.log.write 'Preparing server to start'
done = do @async
start (err) ->
grunt.log.write "server running at localhost:4000"
使用grunt-contrib-watch插件运行watch任务:
I also want to run the "watch" task using grunt-contrib-watch plugin:
grunt.initConfig
watch:
coffee:
files: ['public/coffee/**/*.coffee']
tasks: ['coffee']
jade:
files: ['public/jade/**/*.jade']
tasks: ['jade']
less:
files: ['public/less/**/*.less']
tasks: ['less']
问题是如何使这两个任务服务器)同时运行?我想有一个服务器启动和运行,并不想重新加载它每次一些客户端代码改变。提前感谢
The question is: How to make this two tasks (watch and server) run simultaneously? I want to have a server up and running and don't want to reload it every time some client-side code is changed. Thanks in advance
推荐答案
将其添加到您的观察任务中,摆脱 done = do @
Prefix it to your watch tasks, and get rid of the done = do @async
inside the server task.
tasks:['server','coffee']
您希望在Grunt配置中指定一个选项,使服务器任务成为长时间运行。然后你可以调用 @async
仅当你需要它长时间运行(没有watch任务)。
You want to specify an option in your Grunt configuration for the server task to be "long-running" or not. Then you can call @async
only if you need it to be long running (without the watch task).
这篇关于使用grunt运行两个异步任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!