Course contentsShow
← Web Development
Lesson 1394 of 2,98225. Build Tools and BundlersFree lesson

Webpack Dev Server

Setting up webpack-dev-server for hot module replacement and live reloading during development.

Webpack Dev Server

You'll learn how to set up webpack-dev-server to provide instant feedback during development with automatic reloading and hot module replacement.

What is Webpack Dev Server?

Think of webpack-dev-server as a watchful assistant that rebuilds your project and refreshes your browser every time you save a file. Instead of manually running webpack and hitting refresh after every code change, this development server automates the entire feedback loop.

Core Functionality

When you run webpack-dev-server, it starts a local web server (typically at http://localhost:8080) that serves your bundled application from memory—not from disk. This means faster rebuilds since nothing writes to actual files during development.

The server watches your source files. When you change a CSS rule, update a component, or modify any file webpack tracks, the server:

  1. Rebuilds only what changed
  2. Pushes updates to your browser
  3. Refreshes the page automatically (or updates modules without refresh using HMR)

Basic Setup

First, install it:

npm install --save-dev webpack-dev-server

Then configure it in your webpack.config.js:

module.exports = {
  mode: 'development',
  devServer: {
    static: './dist',
    hot: true,
    port: 8080,
    open: true
  }
};

Run it with:

npx webpack serve

The hot: true option enables Hot Module Replacement (HMR)—modules update in the browser without a full page reload, preserving application state. The open: true option launches your browser automatically.

Key Takeaway: Webpack Dev Server creates a fast development environment with automatic rebuilding, live reloading, and hot module replacement, eliminating manual build-refresh cycles.