grunt: watch command never runs when including other tasks in registerTask method
grunt-contrib-watch, gruntjs, jekyll
Solution
The `server` option makes the task block since it's persistent. You can either use the tasks `watch` option or something like grunt-concurrent to run `jekyll` and `watch` concurrently:
grunt.initConfig({
concurrent: {
target: {
tasks: ['jekyll:server', 'watch'],
options: {
logConcurrentOutput: true
}
}
}
});
grunt.loadNpmTasks('grunt-concurrent');
grunt.registerTask('default', ['concurrent:target']);
Problem
I'm having some unexpected behavior with my Gruntfile. I've registered a task that looks like this: `grunt.registerTask('dev', ['jekyll:server', 'watch:jekyll'])` with the hopes that it will sequentially start a jekyll server, and then watch my project for specific file changes (using the `grunt-contrib-watch` plugin). Once it detects those changes, it would re-run `jekyll:server` automatically. The problem I'm having is that when I run `grunt dev`, it will start the Jekyll server, but it will not run the `watch` commands. However, if I remove the server task from `grunt dev`, it will run the `watch` command as expected. Below is the contents of my Gruntfile. Can anyone help me understand what is happening? ``` module.exports = function(grunt) { // Project configuration. grunt.initConfig({ jekyll: { server : { server: true, server_port: 4000, exclude: ['node_modules'] }, prod: { dest: './_site-release' } }, watch: { jekyll: { files: ['_posts/**/*.md', '_layout/*.html', '_includes/*.html', 'index.html'], tasks: ['jekyll:server'] } } }); grunt.loadNpmTasks('grunt-jekyll'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', 'jekyll:server'); grunt.registerTask('dev', ['jekyll:server', 'watch:jekyll']); grunt.registerTask('release', 'jekyll:prod'); }; ```