0.1.2 • Published 10 years ago

rocketmake-watch v0.1.2

Weekly downloads
1
License
MIT
Repository
-
Last release
10 years ago

rocketmake-watch

This module provides gulp watch and optional (browser-sync) serve

The module exports a watch function and a default serveOptions object (a browser-sync init object)

Watch and Serve

If you want to watch files and serve content (using the default options)

var rmwatch = require("rocketmake-watch");

var watcher = rmwatch.watch([
  {path:"source/**/*.ts", tasks:["build"]},
  {path:"index.html"},
  {path:"style/*.sass", tasks:["sass"]}
], rmwatch.serveOptions);

gulp.task("watch", ["build"], watcher);

In the above example all the watch paths will re-trigger browser-sync to reload the browser.

If you want the watch paths to NOT invoke a browser refresh, add the withoutReload property with a truthy value.

var watcher = rmwatch.watch([
  {path:"source/**/*.ts", tasks:["build"]},
  {path:"index.html", withoutReload: true},
  {path:"style/*.sass", tasks:["sass"]}
], rmwatch.serveOptions);

rmwatch.serveOptions defaults to:

{
  open: false,
  port: 9000,
  server: {
    baseDir: ['.'],
    middleware: function (req, res, next) {
      res.setHeader('Access-Control-Allow-Origin', '*');
      next();
    }
  }
}

Watch only

If you only want to watch files, simply omit the last parameter of watch! (NOTE: the withoutReload property is a noop without serve)

var rmwatch = require("rocketmake-watch");

var watcher = rmwatch.watch([
  {path:"source/**/*.ts", tasks:["build"]},
  {path:"index.html"},
  {path:"style/*.sass", tasks:["sass"]}
]);

gulp.task("watch", ["build"], watcher);