watchpack
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
async | 2.6.4 | 120.04 kB | MIT | prod | |
chokidar | 1.7.0 | 22.33 kB | MIT | prod | 8 2 |
graceful-fs | 4.2.11 | 9.57 kB | ISC | prod |
Watchpack is a powerful wrapper library used for directory and file watching. In essence, it provides a high-level API for monitoring changes in your file system. It relies on a three-tier design to ensure that only one watcher exists per directory, helping to keep the watcher count minimal. The functionality of Watchpack extends beyond merely observing changes. It can also commence watching in the past, which allows watching to begin after data has been read from the file. This utility also caters to symlink watchers, choosing not to follow symlinks directly but rather to observe them independently.
To utilize Watchpack in your project, you begin by installing the package via npm and then require it in your JavaScript file. The basic steps involve creating a new Watchpack instance and defining its options such as aggregateTimeout
, poll
, followSymlinks
, and ignored
. Then, you use the wp.watch()
function to start watching your selected files and directories.
Here's a quick usage walkthrough in code:
// Required: Step 1 - Import Watchpack
var Watchpack = require("watchpack");
// Required: Step 2 - Create a new Watchpack instance with specified options
var wp = new Watchpack({
aggregateTimeout: 1000,
poll: true,
followSymlinks: true,
ignored: "**/.git"
});
// Required: Step 3 - Start watching your desired files and directories
wp.watch({
files: myListOfFiles,
directories: myListOfDirectories,
missing: myListOfNotExistingItems,
startTime: Date.now() - 10000
});
You can also add event listeners to your Watchpack instance to react when changes, removals, or groups of events (aggregated) occur. Additionally, facilities for pausing, closing, and retrieving aggregated info are part of the Watchpack utility.
Remember that customization options like aggregateTimeout
, poll
, followSymlinks
, and ignored
can greatly impact how Watchpack performs in your unique scenario. Ensure you understand what each of these configurations entails to utilize Watchpack to its fullest potential.
For documentation regarding the use of Watchpack, you can refer to the README document on its Github repository page - https://github.com/webpack/watchpack. The README includes a thorough explanation of watchpack's concept, its API, and usage examples. This will guide you in understanding how to integrate and customize Watchpack in your project.