Using gulp watchers

gulp allows you to create tasks that can be run through the command line. You can install plugins for it so you can do things like minify Javascript, Stylesheets…

gulp also comes with watchers, you can check files for changes and if a file change you can run tasks.

import gulp = require("gulp");
import concat = require("gulp-concat");
gulp.task("watch", () =>
{
    // if any js file under gulpsample folder changes
    // run "helloworld" task
    var watcher = gulp.watch("./gulpsample/**/*.js", ["helloworld"]);

    watcher.on("change", function (event)
    {
        // when the change event happens, run this first
        console.log("File " + event.path + " was " + event.type + ", running tasks...");

        // then run tasks specified above (if any)
    });
});

You can watch an example in here:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s