Grunt

Articles
Resources

build-tools

Grunt was the first task runner to achieve critical mass, but there were a 
number of issues:

1. Grunt requires plug-ins for basic functionality such as file-watching
2. Grunt plug-ins often perform multiple tasks which made customization 
   awkward.
3. JSON configuration could become unwieldly for all but the most basic tasks.
4. Tasks could run slowly because Grunt saved files between every processing 
   steps.

Many issues were addressed, but Gulp had already arrived and offered a number 
of improvements:

1. Features such as file watching were built-in.
2. Gulp plug-ins were mostly designed to do a single job.
3. Gulp uses JavaScript configuration code which was less verbose, easier to 
   read, simpler to modify.
4. Gulp was faster because it uses Node streams to pass data through a series 
   of piped plug-ins.  Files were only written at the end of the task.

Gulp itself is not perfect, and new task runners such as http://broccolijs.com/, 
http://brunch.io/ and https://webpack.github.io/ have also been competing for 
developer attention.  More recently, npm itself has been touted as a simpler 
option. All have their pros and cons.

https://www.sitepoint.com/guide-to-npm-as-a-build-tool/

What is Grunt?

Grunt is a JavaScript Task Runner. It is a server-side build tool.

How can we use Grunt?

npm install -g grunt-cli
npm install grunt --save-dev
npm install grunt-contrib-jshint --save-dev
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: 'src/<%= pkg.name %>.js',
        dest: 'build/<%= pkg.name %>.min.js'
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default task(s).
  grunt.registerTask('default', ['uglify']);

};
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License