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"
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
Prefix it to your watch tasks, and get rid of the
done = do @asyncinside the server task.tasks: ['server', 'coffee']You want to specify an option in your Grunt configuration for the server task to be “long-running” or not. Then you can call
@asynconly if you need it to be long running (without the watch task).