sane vs chokidar vs gaze vs node-watch vs watchpack
ファイル監視ライブラリ
sanechokidargazenode-watchwatchpack類似パッケージ:

ファイル監視ライブラリ

ファイル監視ライブラリは、ファイルシステムの変更を監視し、変更があった場合に特定のアクションを実行するためのツールです。これにより、開発者はファイルの変更をリアルタイムで検出し、自動ビルドやリロードなどのプロセスを効率化できます。これらのライブラリは、特に開発環境での作業をスムーズにし、開発者の生産性を向上させることを目的としています。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
sane4,562,788388-345年前MIT
chokidar011,96582.1 kB354ヶ月前MIT
gaze01,155-688年前MIT
node-watch034126.1 kB83年前MIT
watchpack039695.7 kB132ヶ月前MIT

機能比較: sane vs chokidar vs gaze vs node-watch vs watchpack

パフォーマンス

  • sane:

    Saneは、ファイル変更の検出を効率的に行い、大規模なプロジェクトでのパフォーマンスを重視しています。

  • chokidar:

    Chokidarは、ファイルシステムの変更を効率的に監視するために、ネイティブのファイル監視機能を使用します。これにより、大量のファイルを持つプロジェクトでも高いパフォーマンスを維持できます。

  • gaze:

    Gazeは、少数のファイルを監視する際に効果的ですが、大規模なプロジェクトではパフォーマンスが低下する可能性があります。

  • node-watch:

    Node-watchは、シンプルな実装でありながら、基本的なパフォーマンスを提供しますが、大規模なファイル監視には向いていません。

  • watchpack:

    Watchpackは、Webpackと連携して動作し、ビルドプロセスのパフォーマンスを最適化します。

APIの使いやすさ

  • sane:

    Saneは、少し複雑なAPIを持っていますが、柔軟性が高く、カスタマイズが可能です。

  • chokidar:

    Chokidarは、直感的で使いやすいAPIを提供し、設定が簡単です。

  • gaze:

    Gazeは、シンプルなAPIを持ち、すぐに使い始めることができるため、初心者にも優しいです。

  • node-watch:

    Node-watchは、非常にシンプルなAPIを提供し、簡単に導入できます。

  • watchpack:

    Watchpackは、Webpackとの統合を考慮したAPIを提供しており、特定のニーズに応じた設定が可能です。

監視対象のファイル数

  • sane:

    Saneは、大規模なファイル監視に対応しており、効率的に動作します。

  • chokidar:

    Chokidarは、大量のファイルを同時に監視することができ、特に大規模なプロジェクトに適しています。

  • gaze:

    Gazeは、少数のファイルを監視するのに適しており、シンプルなプロジェクトに向いています。

  • node-watch:

    Node-watchは、少数のファイルを監視するのに最適で、軽量な監視が可能です。

  • watchpack:

    Watchpackは、複数のファイルを監視するために設計されており、特にビルドツールとの統合に優れています。

エコシステムとの統合

  • sane:

    Saneは、他のツールとの統合が容易で、特に大規模なプロジェクトでの使用に適しています。

  • chokidar:

    Chokidarは、さまざまなツールやフレームワークと簡単に統合でき、柔軟性があります。

  • gaze:

    Gazeは、他のツールとの統合が少し難しい場合がありますが、基本的な使用には問題ありません。

  • node-watch:

    Node-watchは、他のツールとの統合が容易で、シンプルなプロジェクトに適しています。

  • watchpack:

    Watchpackは、Webpackとの統合を前提に設計されており、ビルドプロセスを効率化します。

メンテナンス性

  • sane:

    Saneは、活発にメンテナンスされており、最新の機能が追加されています。

  • chokidar:

    Chokidarは、活発にメンテナンスされており、最新の技術に対応しています。

  • gaze:

    Gazeは、比較的メンテナンスが行われていますが、更新頻度は低いです。

  • node-watch:

    Node-watchは、シンプルな実装のため、メンテナンスが容易です。

  • watchpack:

    Watchpackは、Webpackの一部としてメンテナンスされており、安定性が高いです。

選び方: sane vs chokidar vs gaze vs node-watch vs watchpack

  • sane:

    Saneは、ファイル監視のための効率的な方法を提供し、特に大規模なプロジェクトでのパフォーマンスを重視する場合に適しています。

  • chokidar:

    Chokidarは、高速で効率的なファイル監視が必要な場合に最適です。特に大規模なプロジェクトや多くのファイルを扱う場合に優れたパフォーマンスを発揮します。

  • gaze:

    Gazeは、シンプルなAPIを提供し、少数のファイルを監視する場合に適しています。設定が簡単で、すぐに使い始めることができます。

  • node-watch:

    Node-watchは、シンプルで軽量な監視が必要な場合に選択肢となります。特に小規模なプロジェクトや簡単なタスクに向いています。

  • watchpack:

    Watchpackは、Webpackなどのビルドツールと統合するために設計されており、複雑なビルドプロセスを持つプロジェクトに最適です。

sane のREADME

Try on repl.it CI

sane

I've been driven to insanity by node filesystem watcher wrappers. Sane aims to be fast, small, and reliable file system watcher. It does that by:

  • By default stays away from fs polling because it's very slow and cpu intensive
  • Uses fs.watch by default and sensibly works around the various issues
  • Maintains a consistent API across different platforms
  • Where fs.watch is not reliable you have the choice of using the following alternatives:

Install

$ npm install sane

How to choose a mode

Don't worry too much about choosing the correct mode upfront because sane maintains the same API across all modes and will be easy to switch.

  • If you're only supporting Linux and OS X, watchman would be the most reliable mode
  • If you're using node > v0.10.0 use the default mode
  • If you're running OS X and you're watching a lot of directories and you're running into https://github.com/joyent/node/issues/5463, use watchman
  • If you're in an environment where native file system events aren't available (like Vagrant), you should use polling
  • Otherwise, the default mode should work well for you

API

sane(dir, options)

Watches a directory and all its descendant directories for changes, deletions, and additions on files and directories.

var watcher = sane('path/to/dir', {glob: ['**/*.js', '**/*.css']});
watcher.on('ready', function () { console.log('ready') });
watcher.on('change', function (filepath, root, stat) { console.log('file changed', filepath); });
watcher.on('add', function (filepath, root, stat) { console.log('file added', filepath); });
watcher.on('delete', function (filepath, root) { console.log('file deleted', filepath); });
// close
watcher.close();

options:

  • glob: a single string glob pattern or an array of them.
  • poll: puts the watcher in polling mode. Under the hood that means fs.watchFile.
  • watchman: makes the watcher use watchman.
  • watchmanPath: sets a custom path for watchman binary.
  • watchexec: makes the watcher use watchexec.
  • dot: enables watching files/directories that start with a dot.
  • ignored: a glob, regex, function, or array of any combination.

For the glob pattern documentation, see micromatch. If you choose to use watchman you'll have to install watchman yourself). If you choose to use watchexec you'll have to install watchexec yourself). For the ignored options, see anymatch.

sane.NodeWatcher(dir, options)

The default watcher class. Uses fs.watch under the hood, and takes the same options as sane(dir, options).

sane.WatchmanWatcher(dir, options)

The watchman watcher class. Takes the same options as sane(dir, options).

sane.Watchexec(dir, options)

The watchexec watcher class. Takes the same options as sane(dir, options).

sane.PollWatcher(dir, options)

The polling watcher class. Takes the same options as sane(dir, options) with the addition of:

  • interval: indicates how often the files should be polled. (passed to fs.watchFile)

sane.{Node|Watchman|Watchexec|Poll}Watcher#close

Stops watching.

sane.{Node|Watchman|Watchexec|Poll}Watcher events

Emits the following events:

All events are passed the file/dir path relative to the root directory

  • ready when the program is ready to detect events in the directory
  • change when a file changes
  • add when a file or directory has been added
  • delete when a file or directory has been deleted

CLI

This module includes a simple command line interface, which you can install with npm install sane -g.

Usage: sane <command> [...directory] [--glob=<filePattern>] [--poll] [--watchman] [--watchman-path=<watchmanBinaryPath>] [--dot] [--wait=<seconds>]

OPTIONS:
    --glob=<filePattern>
      A single string glob pattern or an array of them.

    --ignored=<filePattern>
      A glob, regex, function, or array of any combination.

    --poll, -p
      Use polling mode.

    --watchman, -w
      Use watchman (if available).

    --watchman-path=<watchmanBinaryPath>
      Sets a custom path for watchman binary (if using this mode).

    --dot, -d
      Enables watching files/directories that start with a dot.

    --wait=<seconds>
      Duration, in seconds, that watching will be disabled
      after running <command>. Setting this option will
      throttle calls to <command> for the specified duration.
    --quiet, -q
      Disables sane's console output

    --changes-only, -o
      Runs <command> only when a change occur. Skips running <command> at startup

It will watch the given directory and run the given every time a file changes.

CLI example usage

  • sane 'echo "A command ran"'
  • sane 'echo "A command ran"' --glob='**/*.css'
  • sane 'echo "A command ran"' site/assets/css --glob='**/*.css'
  • sane 'echo "A command ran"' --glob='**/*.css' --ignored='**/ignore.css'
  • sane 'echo "A command ran"' --wait=3
  • sane 'echo "A command ran"' -p

License

MIT

Credits

The CLI was originally based on the watch CLI. Watch is licensed under the Apache License Version 2.0.