How to compress js files?

First you have to install all npm depedecy (package.json)

{
  "name": "gruntFirst",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-uglify": "~0.5.1"
  }
}
npm install

Now you have to create Gruntfile.js with configuration

'use strict';

module.exports = function (grunt) {

	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		uglify: {
			development: {
				files: {
					'app/output.min.js': ['app/*.js']
				}
			},
			options: {

			}
		}
	});

	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.registerTask('default', ['uglify']);
};

And that is all !!!

grunt

or

grunt uglify

Result

input

var testA = '';
var testB = '';

var somFun = function (longName, longNameTwo) {
	return longName + longNameTwo;
}
var testC = '';
var testD = '';

output

var testA="",testB="",testC="",testD="",testA="",testB="",somFun=function(a,b){return a+b},testC="",testD="",testA="",testB="",somFun=function(a,b){return a+b},testC="",testD="";