Grunt script for minifying all JS file

These are some small Grunt script for minifying all JS file . just follow small steps and complete your minifying code. no neeed for external links and other plugins. we provide you easiest code of Grunt script for minifying all JS file.

Grunt script for minifying all JS file

Step1: Install Node JS.

Step 2:  Install grunt CLI

npm install -g grunt-cli

install node

Step 3: Create a new folder and name it anything you want. avoid any symbolic names.

Step 4: Open CMD navigate to the folder you created and run following command. Following code will create package.json which is required to configure node program.

npm init

Step 5: Run following command to install grunt in your folder.

using command promt.

npm install -S grunt

Step 6: Let’s now install uglify.

paste this code

npm install grunt-contrib-uglify --save-dev

Step 7: Now Create Two more folder called: “js” and “jsmin”. js folder will contain all your JavaScript file & when task is finished you will get minified file in “jsmin” folder.

Step 8: Create Gruntfile.js and add following code inside it.


module.exports = function(grunt){

// Project configuration.
grunt.initConfig({
uglify: {
build: {
files: [{
expand: true,
src: '**/*.js',
dest: 'jsmin',
cwd: 'js',
ext: '.min.js'
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
};

Step 9: Run Uglify using following command.

grunt uglify

Step 10: Now All your JS file will be compressed and saved in jsmin folder.

Aumkar Thakur

Owner @ howlthemes.com

you can also ask your question in comment section. Post your programming issues and questions related to JS , jquery, PHP, HTML, Apache, Bootstrap, Mysql .