npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wtch

v4.0.1

Published

small livereload/watch command line utility

Downloads

114

Readme

wtch

stable

A small command-line app that watches for file changes and triggers a live-reload on file save (using LiveReload). Watches the current working directory for js,html,css file changes. Ignores .git, node_modules, and bower_components, and other hidden files.

npm install wtch -g

#start watching ..
wtch

You can use garnish for pretty-printing logs and limiting log level.

wtch | garnish --level debug

See setup for a basic how-to, and tooling for more advanced uses with browserify, watchify, etc.

PRs/suggestions welcome.

Usage

NPM

Usage:
    wtch [globs] [opts]

Options:
    --dir -d        current working directory to watch (defaults to cwd)
    --extension -e  specifies an extension or a comma-separated list (default js,css,html)
    --event         the type of event to watch, "all" or "change" (default "change")
    --port -p       the port to run livereload (defaults to 35729)
    --poll          enable polling for file watching

By default, it looks for **/* with the specified extensions. If globs is specified, they will override this behaviour. So you can do this to only watch a single file:

wtch bundle.js

API

live = wtch(glob, [opt])

Returns a through stream that watches the glob (or array of globs) and returns an event emitter.

Supported options:

  • cwd the current working directory for chokidar
  • poll whether to use polling, default false
  • event the type of event to watch, can be "change" (default, only file save) or "all" (remove/delete/etc)
  • port the port for livereload, defaults to 35729
  • ignoreReload allows ignoring LiveReload events for specific files; can be a file path, or an array of paths, or a function that returns true to ignore the reload, Example:
wtch('**/*.js', { 
  ignoreReload: function(file) {
    //don't trigger LiveReload for this file
    if (file === fileToIgnore)
      return true
    return false
  } 
})
  //instead, manually decide what to do when that file changes
  .on('watch', handler)

live.on('connect')

An event dispatched when the connection to live-reload server occurs.

live.on('watch')

An event dispatched when file change occurs. The first parameter is event type (e.g. "change"), the second is file path.

live.on('reload')

An event dispatched after the live reload trigger. First parameter will be the file path.

LiveReload Setup

There are two common ways of enabling LiveReload.

Script Tag

You can insert the following script tag in your HTML file. This will work across browsers and devices.

<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>

Or you could use inject-lr-script to inject it while serving HTML content.

Browser Plugin

First, install the LiveReload plugin for your browser of choice (e.g. Chrome).

Now, install some tools globally.

npm install wtch http-server garnish -g

Create a basic index.html file that references scripts and/or CSS files.

Then, you can run your development server like so:

http-server | wtch | garnish

Open localhost:8080 and enable LiveReload by clicking the plugin. The center circle will turn black. You may need to refresh the page first.

Click to enable

Now when you save a JS/HTML/CSS file in the current directory, it will trigger a live-reload event on your localhost:8080 tab. CSS files will be injected without a page refresh.

Tooling

This can be used for live-reloading alongside wzrd, beefy and similar development servers. For example:

wzrd test/index.js | wtch --dir test -e js,css,es6 | garnish

It can also be used to augment watchify with a browser live-reload event. This is better suited for larger bundles.

watchify index.js -o bundle.js | wtch bundle.js

See this package.json's script field for more detailed examples.

License

MIT, see LICENSE.md for details.