Easy Grunt watch shortcut for Windows

To avoid typing that long path on your local server everytime you work on your project, create a batch file on your command prompt where it opens.

This applies if you have already installed the package.

  1. Create a file yourprojectname.bat on the folder where your cmd opens. In my case i.e, C:\Users\MyPCname>
  2. Open it and type in these commands on the first line:
    cd /d C:\wherever\your\wordpress\project\theme\directory\is
  3. On the second line, activate grunt, type:
    grunt watch
  4. save

Now you don’t have to type that long path again. All you have to do is type that batch file name on the command prompt.

Hope it helps.
Please share if you have much easy way over this. Thank you.

Easier still.

Create grunt-watch.bat in the project theme directory. Skip step 2. Double-click in Windows Explorer to run.

1 Like

Here is the best practice way of setting up a command shortcut for use in your Roots project directory on windows. I recommend this, so your command prompt environment is setup correctly for use of node.js and the npm command. If you installed node.js correctly this is not really needed, but ensures a proper enviroment and quick start.

The nice thing about this is that you can put these shortcuts anywhere ( I keep them on my desktop for my active projects and store the original copy in the project for later quick copy to anywhere).

  1. Create a Shortcut, right click >> properties >> shorcut tab

  2. Make Target: value as below (replace directories to follow your install dirs)

    C:\Windows\System32\cmd.exe /k “C:\Program Files\nodejs\nodevars.bat”

  3. Make the Start in: value as below (replace with your path to the roots template in each project)


Now you are ready to run your npm commands and grunt.
You can even change icon and colors for each project shortcut.
You can also change how you run the window (ie maximized, etc)
When you double-click the shortcut the nodejs\nodevars.bat will run and print a message telling you something like:
“Your environment has been set up for using Node.js 0.10.18 (x64) and npm.”

You could run this shortcut command as administrator also, but not really needed.
I don’t waist time creating bat files for “npm install” and “grunt watch”, because they are as easy to type as typing in the batch command name.
Also npm install is only ran once to get grunt loaded in your node_modules folder for each roots theme anyway.

Hope this helps someone out.

1 Like

Great suggestions. I edited to the topic to reflect that this is for Windows.