watchify-middleware is a lightweight HTTP middleware designed to enhance the development experience when working with Watchify and Browserify. It prevents stale or empty bundles from being served by suspending the server response until the bundle is ready. The middleware, currently at version 1.9.1 (last published in 2017), differentiates itself by removing the default 600ms rebuild delay common in Watchify, offering immediate feedback, and providing an optional browser-based error handler. It exposes timing information via a 'log' event and facilitates seamless integration into Node.js HTTP servers or frameworks like Express, making it ideal for rapid iteration cycles during web development. Its release cadence has been infrequent, with no major updates since its last stable release, positioning it as a mature, maintenance-mode utility.
npm install watchify-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up a basic HTTP server that serves an HTML page with a 'bundle.js' script. The script is generated by Browserify and hot-reloaded by watchify-middleware, demonstrating how to integrate the middleware to serve continuously updated JavaScript bundles.
If a delay is desired (e.g., for large projects or frequent, rapid file changes), reintroduce it via the `delay` option: `watchifyMiddleware(bundler, { delay: 600 })`.To receive 'error' events, ensure `errorHandler` is `false`. If using a custom `errorHandler` function, handle logging or side effects within that function. Be mindful that using `errorHandler: true` will inject client-side `console.error` calls into your bundle.
When creating your Browserify instance, always include `{ cache: {}, packageCache: {}, plugin: [require('watchify')] }` in its options, along with `basedir` for proper resolution.This is intended behavior. Communicate this characteristic to developers. Ensure your client-side code is robust enough to handle potentially longer response times for the bundle. The 'log' events can be used to monitor rebuild status on the server.
Ensure that the `app.js` (or your entry file) exists at the path relative to `basedir` provided to Browserify, or specify the full absolute path.
Either stop the process currently using port 8000 (e.g., kill any lingering Node.js processes) or configure your server to listen on a different, available port.
Ensure your `browserify` configuration includes `{ cache: {}, packageCache: {}, plugin: [require('watchify')] }`.Check the server console for 'log' events from watchify-middleware, indicating if a rebuild is in progress. If the server hangs indefinitely, ensure there are no errors in your `browserify` setup or your application code that are preventing a successful bundle completion.
No dependency data recorded yet.