Monday, April 10, 2017

Getting Grunt to run when deploying to a Windows server

I use Grunt to process my website css/js/etc files, which is quite handy. When deploying to a server, you do need to make sure that the files get processed as well. One way to do that is to install grunt on the server itself, and either run your grunt production task on deploy, or keep grunt running on the server with a watch task.

This is a short guide on how to run grunt as a Scheduled Task on a Windows server. (This assumes that you have already added a "watch" task on your grunt production task.)

  • Create a .bat file in the root website directory, with the only content being "grunt" or whichever grunt task you want to run.
  • In Windows Server Manager, click on Configuration > Task Scheduler > Task Scheduler Library > Microsoft > Windows
  • Click Create Basic Task
    • Enter the name and description, click Next
    • Select "When the computer stats" for when the task should start and click Next
    • Under What action do you want the task to perform, select "Start a program" and click Next
    • Under Action > Program/script type in the name of the .bat file (don't use Browse), and under Start in type in the full path to the website directory (if you don't do this and use Browse to path to the file it won't run). Click Next and Finish to finish creating have it auto open the properties.
  • In the Properties pop-up dialog, under Security options, select "Run whether user is logged on or not" and "run with highest privileges"


No comments:

Post a Comment