Socket
Socket
Sign inDemoInstall

webpack-dev-middleware

Package Overview
Dependencies
59
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    webpack-dev-middleware

Offers a dev middleware for webpack, which arguments a live bundle to a directory


Version published
Weekly downloads
19M
increased by8.29%
Maintainers
1
Install size
11.3 MB
Created
Weekly downloads
 

Package description

What is webpack-dev-middleware?

webpack-dev-middleware is a package that provides a simple way to serve and live reload webpack bundles for development purposes. It's designed to be used with a Node.js server, such as Express, and it allows developers to serve the webpack-generated files without writing them to disk, providing a faster development experience.

What are webpack-dev-middleware's main functionalities?

Serving Webpack Bundles

This code sample demonstrates how to set up webpack-dev-middleware with an Express server. It serves the files generated by webpack based on the provided configuration.

const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const config = require('./webpack.config.js');
const compiler = webpack(config);

const app = express();

app.use(webpackDevMiddleware(compiler, {
  publicPath: config.output.publicPath
}));

app.listen(3000, function () {
  console.log('Example app listening on port 3000!\n');
});

Enabling Hot Module Replacement (HMR)

This code sample shows how to enable Hot Module Replacement (HMR) in conjunction with webpack-dev-middleware. It requires an additional package, webpack-hot-middleware, to work.

const webpackHotMiddleware = require('webpack-hot-middleware');

app.use(webpackDevMiddleware(compiler, {
  publicPath: config.output.publicPath
}));

app.use(webpackHotMiddleware(compiler));

Other packages similar to webpack-dev-middleware

Readme

Source

webpack-dev-middleware

THIS MIDDLEWARE SHOULD ONLY USED FOR DEVELOPMENT!

DO NOT USE IT IN PRODUCTION!

What is it?

It's a simple wrapper middleware for webpack. It serves the files emitted from webpack over a connect server.

It has a few advantages over bundling it as files:

  • No files are written to disk, it handle the files in memory
  • If files changed in watch mode, the middleware no longer serves the old bundle, but delays requests until the compiling has finished. You don't have to wait before refreshing the page after a file modification.
  • I may add some specifiy optimation in future releases.

Usage

var webpackMiddleware = require("webpack-dev-middleware");
app.use(webpackMiddleware(...));

Use the webpackMiddleware function like the webpack function, but without callback. Example usage:

app.use(webpackMiddleware(__dirname, "./lib/file", {
	watch: true,
	debug: true,
	publicPrefix: "http://localhost:8080/assets/",
	output: "bundle.js",
	outputPostfix: ".bundle.js",
	// ... more webpack config options
}));

options.watch = true

This is not required, but recommendated to get the best out of the middleware.

options.publicPrefix

The prefix for request that should be handled.

options.output, options.outputPostfix

The filename for the bundle.

options.verbose

Verbose output of the statistics.

All other options like webpack

FAQs

Last updated on 11 Sep 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc