Performance Zone is brought to you in partnership with:

A GNU/Linux g33k CLI+Web loving computer polyglot. Hemanth is a DZone MVB and is not an employee of DZone and has posted 16 posts at DZone. You can read more from them at their website. View Full User Profile

Live Reload with Grunt

12.18.2012
| 3481 views |
  • submit to reddit

Sometime back I had published an entry on Node Packing with grunt but live reload has been so fascinating to most of the webdevs, it would be worth to make your own tiny server that reloads files as and when it gets edited.

Check out the video DEMO and then read the steps below:

  • Install grunt and grunt-reload : npm install -g grunt grunt-reload

The grunt.js:

module.exports = function (grunt) {
    'use strict';
 
    //initialize grunt with config
    grunt.initConfig({
        //configure grunt-reload
        reload: {
            port: 1337, // LR Port
            liveReload: {},
            proxy: {
                host: 'localhost'
            }
        },
        trigger: {
            watchFile: 'index.html'
        },
        server: {
            port: 8000,
            base: '/labs'
        },
        watch: {
            files: ['/labs/*.html'],
            tasks: 'reload'
        }
    });
 
    //Load the extra tasks from our npm modules
    grunt.loadNpmTasks('grunt-reload');
    grunt.registerTask("run", "server reload watch");
 
};

To start the task just say : $grunt run and have fun!

P.S : grunt-contrib-reload is anyway better, but this is just the raw way of doing it.

Published at DZone with permission of Hemanth Madhavarao, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)