Trying Grunt.js in your projects is the most interesting things that one can adopt in their web development process task. The Grunt ecosystem is one of the biggest js and its growing day-by-day. Grunt can be used with literally hundreds of plug-ins to choose from to mechanize just about anything with a minimum of attempt.
Moreover, if someone hasn’t already built what you require for your project, you can able to author and publish your own Grunt plug-in to npm.
Why Use Grunt?
With Grunt, one can easily catch sloppy code like braceless control statements, unused variables, missing semicolons and trailing whitespace, if he/she is using conjunction with your favorite code-quality tools. It is excellent in finding human errors and not allowing valid and bad written js.
Goal to Adopt Grunt
The main aim to adopt grunt is to do various task like
- monitor our project for changes to SASS files, and use Compass to compile them into CSS.
- monitor our project for changes to HTML and JS files, and use LiveReload to refresh our page.
Basic of grunt setup
Some basic documentation is available with Grunt on their website that allows proper setting of your project. Firstly, Node.js is used by Grunt js and is installed through npm (node’s package manager). Once you have installed all those things properly, you are all set for installing the Grunt CLI globally.
npm install -g grunt-cli
[A valid Gruntfile could not be found. Please see the getting started guide for more information on how to configure grunt: http://gruntjs.com/getting-started Fatal error: Unable to find Gruntfile.]
Above given message were displayed when we were run a grunt in our project directory. Let’s check out a package.json and a Gruntfile.js in the root of our project touch package.json Gruntfile.js
How to upgrade grunt from 0.3 to 0.4
It would be profitable to read the new Getting started guide, if you are already aware of grunt. Grunt, grunt-cli and grunt-init are three parts in which grunt are divided.
- The npm module grunt should be installed to your project locally. it is combination of the code and logic for running tasks, loading plugins, etc.
- The npm module grunt-cli should be installed globally. The grunt command in your PATH is placed in it for executing it anywhere. It doesn’t work by itself, one should have to installed Grunt locally to your project, irrespective of the version
- The init task has been broken into its own npm module, grunt-init. It has be installed globally with npm install -g grunt-init and run with the grunt-init command.
Whether Grunt work on Windows?
One of the best things about Grunt is it easily run on Windows as its Node.js and npm works finely on Windows. However, the most difficult part is Cygwin that bundles an outdated version of Node.js.
It is advisable to use the msysGit installer to install the git binary and the Node.js installer to install the node and npm binaries and also to utilize the built-in Windows command prompt or PowerShell instead of Cygwin.
Adopting Grunt makes you richer with many different things. It provides amazing outcomes to your web development process. If you want to know more about Grunt or have any query, ask through comment section.