How to debug Gruntfile.js using log statements?

In my Grunt file, how can I add log instructions 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'] }, } 
+6
source share
4 answers

Gruntfiles is javascript, so you can use console.log() wherever it is if it is valid javascript.

 grunt.initConfig({ karma: { unit: { configFile: 'build/karma.conf.js' } } }); if (grunt.option('debug')) { console.log(grunt.config('karma.unit.configFile')); } 
+8
source

I'm not what you ask, but if you want to put the debug log in the Gruntfile.js file, have you seen the grunt.log method?

+3
source

It would be nice if it were that simple ... console.log () only outputs client information to the client; however, since you are running on the server side, you will not see anything pop up in the browser console (rather, on the server console, perhaps on your terminal).

There is a way around this thanks to the work of others, for example: https://github.com/ethanl/connect-browser-logger

This will basically cause you to select these server logs for the client. If you do Google, you will find many other solutions (some of which can set breakpoints, execute code, etc.).

Not shabby!

Edit: Christ, I just realized that you want the log to be in your grunt file. This is a slightly different story, but it should still work for you!

+2
source

Various tools exist, such as the node inspector , which will allow you to debug these specific files.

On node inspector (from github page):

node Inspector is a debugger interface for Node.js applications that use the Blink developer tools (formerly WebKit Web Inspector).

There are some excellent answers on this stackoverflow question on how to do this specifically: Using the node inspector with Grunt tasks

0
source

Source: https://habr.com/ru/post/954616/


All Articles