I tried to run the watch task by grunt in node.js but it doesn't work for me (this is what I got):
$ grunt watch
warning: Maximum call stack size exceeded Use --force to continue.
This is the part of the watch task in the Gruntfile.js:
watch: {
less: {
files: 'src/less/*.less',
tasks: ['clean', 'recess', 'copy']
},
js: {
files: 'src/js/*.js',
tasks: ['clean', 'jshint', 'concat', 'uglify', 'copy']
},
theme: {
files: 'src/theme/**',
tasks: ['clean', 'recess', 'copy']
},
images: {
files: 'src/images/*',
tasks: ['clean', 'recess', 'copy']
}
}
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('watch', ['watch']);
u_mulder is correct; simply remove the unnecessary grunt.registerTask('watch', ['watch'])
line from your code and you should be good to go.
Edit: This happens because you are registering a new task that calls itself. Adding a line like grunt.registerTask('watch', ['watch']);
doesn't make sense because it is already defined for you. If this wasn't the case you would have to call grunt.registerTask
for each and every task in your Gruntfile config.
In some cases it might make sense to alias the task with a different name. It would be called with the exact same configuration that you have specified, but aliasing it could save typing. For instance I like to register my available tasks plugin with the 'tasks' alias, so instead of typing grunt availabletasks
I can type grunt tasks
and that saves me some typing. In this instance you could do something like:
grunt.registerTask('w', ['watch']);
And you can then use grunt w
as a shortcut for grunt watch
.