Socket
Socket
Sign inDemoInstall

@types/webpack-dev-middleware

Package Overview
Dependencies
4
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/webpack-dev-middleware

TypeScript definitions for webpack-dev-middleware


Version published
Weekly downloads
96K
increased by5.02%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @types/webpack-dev-middleware?

@types/webpack-dev-middleware provides TypeScript type definitions for the webpack-dev-middleware package, which is a middleware for serving webpack bundles during development. It allows for seamless integration with various server frameworks like Express.

What are @types/webpack-dev-middleware's main functionalities?

Basic Setup

This code sets up a basic Express server that uses webpack-dev-middleware to serve the webpack bundle. The middleware is configured with the webpack compiler and the public path from the webpack 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!');
});

Custom Configuration

This code demonstrates how to customize the webpack-dev-middleware with additional options such as enabling colored stats output and writing files to disk.

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,
    stats: { colors: true },
    writeToDisk: true,
  })
);

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

Using with Hot Module Replacement (HMR)

This code shows how to integrate webpack-dev-middleware with webpack-hot-middleware to enable Hot Module Replacement (HMR) in an Express application.

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

const app = express();

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

app.use(webpackHotMiddleware(compiler));

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

Other packages similar to @types/webpack-dev-middleware

Readme

Source

Installation

npm install --save @types/webpack-dev-middleware

Summary

This package contains type definitions for webpack-dev-middleware (https://github.com/webpack/webpack-dev-middleware).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/webpack-dev-middleware/v3.

Additional Details

Credits

These definitions were written by Benjamin Lim, reduckted, Chris Abrams, and Piotr Błażejewicz.

FAQs

Last updated on 02 Jul 2021

Did you know?

Socket

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc