How to debug Gruntfile.js with log statements?
Solution 1
Gruntfiles are javascript so you can use console.log()
where ever as long as it is valid javascript.
grunt.initConfig({
karma: {
unit: {
configFile: 'build/karma.conf.js'
}
}
});
if (grunt.option('debug')) {
console.log(grunt.config('karma.unit.configFile'));
}
Solution 2
I'm not what you are asking, but if you want to place debug logging in a Gruntfile.js, have you seen the grunt.log method?
Solution 3
It would be nice if it were that easy... console.log() only outputs client-side stuff to the client; however, since you're working on the server-side of things, you won't see anything pop up in the browser console (rather the server console, probably your terminal).
There is a way around this thanks to the work of others, for instance: https://github.com/ethanl/connect-browser-logger
This will basically hoist those server side logs out to the client for you to see. If you do a Google, you'll find a slew of other solutions (some with the ability to set breakpoints, step through code, etc).
Not shabby!
Edit: Christ, I just realized you wanted the logging specifically IN your gruntfile. That's a bit of a different story, but it still should work for you!
Gururaj
Updated on June 24, 2022Comments
-
Gururaj almost 2 years
In my Gruntfile, how can I add log statements, to its processing, as in the following example?
karma: { unit: { configFile: "<%= grunt.option('Debug') ? 'build/karma.conf.js' : '' %>", console.log(configFile), singleRun: true, browsers: ['PhantomJS'] }, }