browserify-dev-bundler
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript maintenance
On-demand browserify bundler middleware for development with watchify support. Version 2.0.0 is the latest stable release, with low release cadence (last release in 2016). It dynamically bundles CommonJS modules via HTTP requests, caching bundles with watchify for fast responses during development. Unlike manual watchify tasks or file-based bundling, it integrates directly as Express middleware, intercepting *.js requests and bundling on the fly. Not suitable for production—use browserify build process instead. Works with Node.js and Express.
Common errors
error Cannot find module 'browserify' ↓
cause Missing peer dependency browserify; not automatically installed with npm install.
fix
Run: npm install browserify watchify --save-dev
error bundler.middleware is not a function ↓
cause Forgetting to instantiate DevBundler with new; calling DevBundler() without new returns a constructor, not an instance.
fix
Use: const bundler = new DevBundler(options); or simply DevBundler(options) (works without new due to internal check).
Warnings
gotcha Middleware matches all *.js files by default; may unintentionally bundle non-module JS files or cause conflicts with static file serving. ↓
fix Use a regex pattern to restrict which URLs are bundled: e.g., bundler.middleware(/^\/js\/(.+)\.js$/).
deprecated watchify is enabled by default, which may cause high memory usage in large projects or when many files change. ↓
fix Set watchify: false if you don't need auto-rebundling, or manually manage watchify instances.
breaking Version 2.0.0 changed the default middleware behavior to intercept all *.js; previous versions used a different default pattern. ↓
fix Update regex patterns if you relied on older defaults; use bundler.middleware(/^\/js\/(.+)\.js$/) to restrict paths.
gotcha addFile option overrides default bundle.add(); using bundle.require() without expose can cause double bundling or missing dependencies. ↓
fix Ensure addFile function uses bundle.require() with expose option for modules that need to be requireable by other bundles.
gotcha bundle-error event does not prevent crashes; unhandled errors may crash the server. ↓
fix Always attach a listener to 'bundle-error' event: bundler.on('bundle-error', err => console.error(err)).
Install
npm install browserify-dev-bundler yarn add browserify-dev-bundler pnpm add browserify-dev-bundler Imports
- DevBundler wrong
import DevBundler from 'browserify-dev-bundler';correctconst DevBundler = require('browserify-dev-bundler'); - middleware wrong
app.use(DevBundler.middleware);correctapp.use(bundler.middleware()); - events wrong
bundler.addEventListener('pre-bundle', ...);correctbundler.on('pre-bundle', (bundle, modName, modPath) => {});
Quickstart
const express = require('express');
const DevBundler = require('browserify-dev-bundler');
const path = require('path');
const app = express();
const bundler = DevBundler({
root: path.join(__dirname, 'public', 'js'),
watchify: true,
debug: true,
transforms: []
});
app.use(bundler.middleware());
app.listen(3000, () => console.log('Dev server on 3000'));
// Request GET /app.js => bundles public/js/app.js