Webpack Development Middleware

8.0.3 · active · verified Wed Apr 22

webpack-dev-middleware is an Express-style development middleware for integrating webpack into a custom Node.js HTTP server environment. It serves the bundles emitted from webpack directly from memory, avoiding disk I/O during development, which significantly speeds up development workflows. The current stable version is 8.0.3, with minor and patch releases occurring frequently as new features are added and bugs are fixed, often driven by updates to webpack itself or compatibility with alternative bundlers like Rspack. Its key differentiators include in-memory file handling, delaying requests until compilation is complete, and robust support for Hot Module Replacement (HMR). This middleware is strictly for development environments and should not be used in production.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up webpack-dev-middleware with an Express application to serve webpack-compiled assets from memory.

import express from 'express';
import webpack from 'webpack';
import middleware from 'webpack-dev-middleware';

const compiler = webpack({
  mode: 'development',
  entry: './src/index.js',
  output: {
    path: '/',
    filename: 'bundle.js',
  },
});

const app = express();

app.use(
  middleware(compiler, {
    publicPath: '/',
    // logLevel: 'warn', // Consider setting this for less verbose output
    // writeToDisk: false, // Files are served from memory by default
  }),
);

app.listen(3000, () => {
  console.log('Webpack dev middleware example app listening on port 3000!');
  console.log('Access your app at http://localhost:3000/bundle.js');
});

view raw JSON →