Using Grunt.js for minification of JS files

What's Grunt? 

It's a task runner.

Who uses Grunt?

But first, what's npm?

and why do we care?

The package.json file

and how to create it?

Install grunt using npm

Add uglify to the package.json

Let's create the Gruntfile.js

Title Text

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      prod: {
        files: minifyFiles
      }, options: {
    	    mangle: true
      },
    }
  });

Initializing grunt

Title Text

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

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

Loading plugins and registering tasks

Things you can do with Grunt

 

So does minification help?

Using grunt.js for minification and beautification

By abijeet

Using grunt.js for minification and beautification

  • 640