Grunt.js is obviously spawning a new node.js process when using grunt's watch task:
http://www.youtube.com/watch?v=fgRlcFt9dkg
As soon as I save my document the default task is executed and (as you can see in the video) there suddenly is a new node.exe process.
This is my gruntfile:
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-yui-compressor');
// Project configuration.
grunt.initConfig({
// Metadata.
meta: {
version: '1.0',
},
banner: '/*! Copyright (c) <%= grunt.template.today("yyyy") %> */\n',
// Task configuration.
concat: {
options: {
banner: '<%= banner %>',
stripBanners: true
},
develop: {
src: ['js/app.main.js', 'js/app/*.js', 'js/app.debug.js', 'js/app.workarounds.js', 'js/app.init.js'],
dest: 'build/js/app.js'
},
production: {
src: ['js/app.main.js', 'js/app/*.js', 'js/app.workarounds.js', 'js/app.init.js'],
dest: 'build/js/app.js'
},
habla_css: {
src: ['build/habla.css'],
dest: 'build/habla.css'
},
wiwo_css: {
src: ['build/wiwo.css'],
dest: 'build/wiwo.css'
},
iefix: {
src: 'js/iefix/*',
dest: 'build/js/iefix.js'
},
libs: {
src: ['js/src/*'],
dest: 'build/js/libs.js'
}
},
clean: {
pre: [
'build'
],
post: 'dest'
},
copy: {
thirdparty: {
files: [
{
expand: true,
src: ['js/jquery.min.js'],
dest: 'build/',
}]
}
},
min: {
options: {
report: false,
banner: '<%= banner %>'
},
app: {
src: ['build/js/app.js'],
dest: 'build/js/app.min.js'
},
iefix: {
src: 'js/iefix.js',
dest: 'build/js/iefix.min.js'
},
libs: {
src: ['js/src/*'],
dest: 'build/js/libs.min.js'
},
},
cssmin: {
options: {
report: false,
banner: '<%= banner %>'
},
icons: {
src: ['build/icons.css'],
dest: 'build/icons.min.css'
},
habla: {
src: ['build/habla.css'],
dest: 'build/habla.min.css'
},
wiwo: {
src: ['build/wiwo.css'],
dest: 'build/wiwo.min.css'
}
},
less: {
icons: {
src: ['less/system/icons.less'],
dest: 'build/icons.css'
},
habla: {
src: ['less/habla.less'],
dest: 'build/habla.css'
},
wiwo: {
src: ['less/wiwo.less'],
dest: 'build/wiwo.css'
}
},
replace: {
production: {
src: 'build/js/app.js',
dest: 'build/js/app.js',
replacements: [{
from: /\s*App.debug.(log|group|groupEnd)\(.*\);/g,
to: ''
},
{
from: 'debug: true',
to: 'debug: false'
}]
},
date: {
src: 'build/js/app.js',
dest: 'build/js/app.js',
replacements: [{
from: '/*!%CURDATE%*/',
to: 'console.log("' + d.replace(/(T|Z)/gi,' ') + '");'
}]
}
},
qunit: {
files: ['tests/**/*.html']
},
watch: {
main: {
files: ['grunt.js', 'js/app.*.js', 'js/**/*', 'less/**/*', 'less/*'],
tasks: ['default'],
options: {
nospawn: true
}
}
}
});
grunt.registerTask('con', ['concat:habla_css', 'concat:wiwo_css', 'concat:iefix', 'concat:libs']);
grunt.registerTask('icons', ['less:icons cssmin:icons']);
grunt.registerTask('test', ['qunit']);
// Default task.
grunt.registerTask('default', ['less:habla', 'less:wiwo', 'concat:develop', 'con', 'replace:date', 'copy:thirdparty', 'clean:post', 'watch']);
grunt.registerTask('release', ['clean:pre', 'less', 'concat:production', 'con', 'replace:production', 'copy:thirdparty', 'min', 'cssmin', 'clean:post']);
};
So is it a grunt bug or a bug in my gruntfile? The grunt version I'm using is 0.4.1 (+ grunt-cli 0.1.9) on Windows 7 x64.
You should not have 'watch' as the final task in your default task sequence. Your watch configuration invokes default, which then spawns another watch task each time. This line is the problem:
grunt.registerTask('default', ['less:habla', 'less:wiwo', 'concat:develop', 'con', 'replace:date', 'copy:thirdparty', 'clean:post', 'watch']);
It should be this instead:
grunt.registerTask('default', ['less:habla', 'less:wiwo', 'concat:develop', 'con', 'replace:date', 'copy:thirdparty', 'clean:post']);
You should simply run grunt:watch in order to watch the files.
And if you want to run the default task sequence without doing watch, then you can simply run grunt
That's it. Thank you!
I optimized it a little bit so I can still run grunt (without to specify the watch parameter):
watch: {
main: {
files: ['grunt.js', 'js/app.*.js', 'js/**/*', 'less/**/*', 'less/*'],
tasks: ['develop']
}
}
grunt.registerTask('develop', ['less:habla', 'less:wiwo', 'concat:develop', 'con', 'replace:date', 'copy:thirdparty', 'clean:post']);
grunt.registerTask('release', ['clean:pre', 'less', 'concat:production', 'con', 'replace:production', 'copy:thirdparty', 'min', 'cssmin', 'clean:post']);
grunt.registerTask('default', ['develop', 'watch']);
Works fine! Thanks!