XClose

Indigo

Home
Menu

Task Runner

Get Grunt running

There are a number of prerequisites for the developer to check before being able to run grunt tasks which are listed below.

For the following steps you will need to run them in your terminal or command prompt depending on OS. For Mac OSX/Unix users you may need to run commands as 'sudo' depending on the directories or files you are writing to.

  • Grunt Cli needs to be globally installed. If you have not done this please run 'npm install -g grunt-cli'
  • You will need to have ruby installed. Type 'ruby --version' to check if you have ruby installed. If you do a version will be returned.
  • You will also need to have 'gem' installed. Again you can check by typing 'gem --version' in you terminal.
  • With Ruby and Gem installed you can install sass by running 'gem install sass'
  • Grunt tasks can be run from any directory with a 'gruntfile.js' file. They will also have a package.json which manages the dependencies. You will need to run 'npm install' to read and install the dependencies. 
  • Finally you can navigate to any of your projects which have a grunt file and you run a grunt task. The default task can be run by simply running 'grunt' in the terminal
  • Note: If a process is currently watching you will need to CTRL+ C to stop it (i.e. grunt watch)

Adding extra tasks

  • To add new grunt modules e.g.grunt contrib sass https://github.com/gruntjs/grunt-contrib-sass in your working directory type 'npm install grunt-contrib-sass --save-dev' note: the '--save-dev' saves this module in the package.json
  • In your grunt file you will then need to load the module. In the above example you would need to add the line grunt.loadNpmTasks('grunt-contrib-sass'); before you are able tot call the modules task
  • To use the task you finally need to have it listed in the array for the grunt task you want to run. The default task is 'default' and can be run by just 'grunt' in your working directory. If you wanted to create a task called 'buildsass' you would add a new registered task with this name e.g. grunt.registerTask('buildsass', ['sass','watch']); The second argument of registerTask accepts an array of tasks to run so to demonstrate I have added the task 'watch' which is commonly used to watch for changes to your files -  https://github.com/gruntjs/grunt-contrib-watch