Watch some files, do a thing

  • gazer

Downloads in past


1.0.07 years ago10 years agoMinified + gzip package size for gazer in KB


Watch some files, do a thing

A simple wrapper for Shama's gaze module that performs an arbitrary command when files change. Like watchify, but for everything.


This works best as a devDependency in the project you plan to use it in:
$ npm install --save-dev gazer

You can easily invoke gazer with npm run via npm scripts that you set up in your package.json. See the usage example below for more details.
If you want to use this everywhere, across multipe projects, you can install it globally, too:
$ npm install -g gazer


$ gazer --pattern "" echo "blorp"

[ changes]

> "blorp"

Arbitrary watch tasks with npm run

If you haven't read substack's post describing lightweight build steps with npm run, I'll give you a moment to get up to speed.
Here's how you might use gazer to run a build task every time a file changes:
  "scripts": {
    "build-less": "lessc public/less/main.less public/css/main.css",
    "watch-less": "gazer -p 'public/less/**/*.less' npm run build-less"

And then start the watcher:
$ npm run watch-less

Double dash

If you need to pass a -p argument to the command you're running, use -- to separate the option arguments from the positional arguments:
$ gazer -p -- echo -p

This feature is provided for free by optimist.