Grunt debugging from Webstorm
19,196
Solution 1
You have to run grunt-cli as a Node application:
- Create a new Node.js Run/Debug configuration: Run->Edit configurations...
- In Path to Node choose your node binary, ie:
/Users/someuser/nvm/v0.10.5/bin/node
- In Working Directory, choose your
Gruntfile.js
directory, ie/Projects/someproject
- In Path to Node App JS File, choose your Grunt CLI path (you can choose the
grunt-cli
symlink created on your node bin directory, WebStorm will use the symlink target), ie:/Users/someuser/nvm/v0.10.5/lib/node_modules/grunt-cli/bin/grunt
(C:\Users\someuser\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
on Windows 7) - In Application parameters enter the Grunt task to run, eg
default
ortest
Click on Run or Debug and you are done :)
Solution 2
I just happened to try this in WebStorm 10 today. I'm not sure if it's a new feature but WebStorm have integrated the steps described by @diego so you don't have to perform them manually:
- Click View > Tool Windows > Grunt to display the Grunt window in WebStorm.
- Right-click on any task and choose "Debug"
You can set breakpoints etc. in Gruntfile.js
just like you would any other file.
Author by
Kamal Reddy
console.log('I am Awesome'); You can donate here(Bitcoin address): 1JWhS3ebNnBpVE2vGXdR8q6igFuoKfMkpC
Updated on June 06, 2022Comments
-
Kamal Reddy almost 2 years
Its possible to run grunt tasks within WebStorm through external tools. However, is it possible to avail debugging with external tools? By running tasks like
grunt server
orgrunt test
within WebStorm, it would make debugging a lot easier if it's possible with external tools like grunt. -
Lance almost 11 yearsIs there a way to config webstorm to run Grunt Test automatically when file is saved? Thanks
-
Diego almost 11 yearsI never did it before, but probably if you go to Project Settings and configure a custom file watch (look for "File Watchers" then click on the plus button at the bottom and choose custom), you can launch node with Grunt each time that a file changes. (I usually use grunt watch in a second terminal instead of using File Watchers)
-
devmiles.com over 10 yearsAny ideas why starting a debug session for this takes a lot of time to start up?
-
Diego over 10 yearsI think that ItelliJ guys are the best to answer that question (you can create a ticket here: youtrack.jetbrains.com/issues). But my bet is that when NodeJS starts in debug mode, probably some V8 optimizations are off, so maybe loading all the dependencies of Grunt with debug support takes more time. Another possible cause could be some network config in your machine (NodeJS debugger uses TCP to expose the debug interface, that's used by WS). But again... my "answers" are just guesses :)
-
ebaranov over 10 yearsI get it works, when I set the "Path to Node App JS file" as path to grunt binary file: "/usr/local/lib/node_modules/grunt-cli/bin/grunt"
-
JonnyReeves over 10 yearsFor me, I used the output of
which grunt
to find the correct Path to Node App JS File -
mikegradek almost 10 yearsStarting Webstorm from the terminal also helps its environment variables available to Webstorm.
-
Stepan Suvorov about 9 yearsstarting from WEbStrom10 it became even more convenient: now you could select grunt on step Run->Edit configurations...
-
br3w5 about 5 yearsYou have to make sure you include any env vars that you have in the run configs because you lose these when going via the Tool Windows via the
Edit 'task' settings...
option when right-clicking