browserify-middleware

raw JSON →
8.1.1 verified Sat Apr 25 auth: no javascript maintenance

Express/Connect middleware for Browserify v2, currently at version 8.1.1. Provides sensible defaults: automatic source maps, file watching in development, minification, gzip, and etag caching in production. Supports serving individual files, directories of files, and npm package bundles with external dependencies for optimized caching. Allows use without Express except for directory serving. Last updated in 2013; depends on browserify >=2.x and uses uglify-js. Compared to alternatives like budo or watchify, it integrates directly as middleware for existing Express apps.

error Cannot find module 'browserify'
cause browserify is not installed as a peer dependency.
fix
npm install browserify --save
error browserify is not a function
cause Incorrect import: trying to use named export instead of default.
fix
Use: var browserify = require('browserify-middleware');
error Uncaught Error: module 'xyz' not found
cause Passed separate arguments instead of array to browserify().
fix
browserify(['module-a', 'module-b']) not browserify('module-a', 'module-b')
deprecated Package uses outdated browserify v2 API and may not work with newer Node.js versions.
fix Consider migrating to modern bundler middleware like budo or webpack-dev-middleware.
gotcha Directory paths are relative to the calling module, not process.cwd().
fix Use __dirname to construct absolute paths: browserify(__dirname + '/client/dir')
gotcha When passing an array of npm packages, they are bundled into a single file exposing require, not separate entries.
fix Use the array form only for shared dependencies; use .external option for external referencing.
npm install browserify-middleware
yarn add browserify-middleware
pnpm add browserify-middleware

Sets up an Express server that serves a browserified version of client/main.js at /js/bundle.js.

var browserify = require('browserify-middleware');
var express = require('express');
var app = express();

app.get('/js/bundle.js', browserify(__dirname + '/client/main.js', {
  // options: external, noParse, cache, etc.
}));

app.listen(3000);
console.log('Server running on port 3000');