Automate AngularJS Build Using Grunt JS(Task Runner)

Grunt is very popular build tool for creation build and deployment of application. Grunt JS is responsible to automate all thing after development, it’s very handy and easy to use, in previous article Grunt – JavaScript Task Runner for Automate Your Development, We have learnt how to install grunt and use GRUNT in your application, here is I am describing use of grunt with angular application.

Why i use angular:

Angular is very popular front-end framework now days, Every back-end language uses angular technology for front end UI creation, Angular application has a lot of js and css file that can be used to concatenate all files and minified these file into single js/css file.

You can also check other tutorial of angular,

What I will do:

We can concatenate all js/css files into single file then minified this js/css file.I am assuming you have installed npm and grunt, if not please refer previous tutorial .

Folder Structure:

grunt task runner with angular

Where As :

.tmp : This folder will store result of concatenate css and js files.
dist : This folder will contain all your build files with minified css and js file.
node_modules: This folder will keep all dependent modules of grunt that you will use in your grunt task runner project that will help to create build.
Source: Your source code of application.

Step 1: We need to create a folder, where we will run grunt task. I have created 'test-grunt' folder.

Step 2:We have created 'source' and 'dist' folder, The source folder will contain your source code files css/style.css,css/bootstrap.css and js/bootstrap.js, js/common.js and /dist folder will store your angularjs build files.

Step 3: I have create package.json file and put the below code into this file.

This file is containing all grunt dependency module list and responsible to load all modules in your application.

Step 4: I have create Gruntfile.js and put the below code into this file.

Above file is responsible to run task for your activities what you defined in this file, the sequence of task run would be as mentioned in last line of this file.

Step 5: Now we have defined which file we used for concatenate and minifying, we will list down all file like below between build comment tag.

Step 6: Now open cmd line and got to project folder and run 'npm install'.
above command will download all dependency files in to your project and kept into node_modules/ folder.

Step 7: Now run 'grunt' command, this will done all tasks of listed grunt file Gruntfile.js, like copy the file and concatenate then minimized all css and js files and store into single file.

You can download source code from below link.

I hope its help, You have any question feel free to drop a mail (find on contact us page).