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 or test

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:

  1. Click View > Tool Windows > Grunt to display the Grunt window in WebStorm.
  2. Right-click on any task and choose "Debug"

You can set breakpoints etc. in Gruntfile.js just like you would any other file.

Share:
19,196
Kamal Reddy
Author by

Kamal Reddy

console.log('I am Awesome'); You can donate here(Bitcoin address): 1JWhS3ebNnBpVE2vGXdR8q6igFuoKfMkpC

Updated on June 06, 2022

Comments

  • Kamal Reddy
    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 or grunt test within WebStorm, it would make debugging a lot easier if it's possible with external tools like grunt.

  • Lance
    Lance almost 11 years
    Is there a way to config webstorm to run Grunt Test automatically when file is saved? Thanks
  • Diego
    Diego almost 11 years
    I 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
    devmiles.com over 10 years
    Any ideas why starting a debug session for this takes a lot of time to start up?
  • Diego
    Diego over 10 years
    I 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
    ebaranov over 10 years
    I 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
    JonnyReeves over 10 years
    For me, I used the output of which grunt to find the correct Path to Node App JS File
  • mikegradek
    mikegradek almost 10 years
    Starting Webstorm from the terminal also helps its environment variables available to Webstorm.
  • Stepan Suvorov
    Stepan Suvorov about 9 years
    starting from WEbStrom10 it became even more convenient: now you could select grunt on step Run->Edit configurations...
  • br3w5
    br3w5 about 5 years
    You 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