Webpack Dev Server

WDS works by holding your bundled files in memoryon the dev server. This allows for the quick diffing and serving of changes to application assets as they change during development. WDS “stores” these files at the output.publicPath. The following gist contains the webpack config I will reference throughout this post. Webpack-dev-server # webpack-dev-server (WDS) is the officially maintained development server running in-memory, meaning the bundle contents aren't written out to files but stored in memory. The distinction is vital when trying to debug code and styles. Npm i webpack-dev-server -save-dev webpack-dev-server is a convenient package for development. Once configured, we can launch a local server to serve our files. To configure webpack-dev-server, open up package.json and add a 'start' script. Webpack-dev-server can be used to quickly develop an application. See the 'How to Develop?' This page describes the options that effect the behavior of webpack-dev-server (short: dev-server).

Use webpack with a development server that provideslive reloading. This should be used for development only.

It uses webpack-dev-middleware under the hood, which providesfast in-memory access to the webpack assets.

Table of Contents

  • Usage

Getting Started

First things first, install the module:

Webpack Dev ServerWebpack

Note: While you can install and run webpack-dev-server globally, we recommendinstalling it locally. webpack-dev-server will always use a local installationover a global one.

Usage

There are two main, recommended methods of using the module:

With the CLI

The easiest way to use it is with the CLI. In the directory where yourwebpack.config.js is, run:

Note: Many CLI options are available with webpack-dev-server. Explore this link.

With NPM Scripts

NPM package.json scripts are a convenient and useful means to run locally installedbinaries without having to be concerned about their full paths. Simply define ascript as such:

And run the following in your terminal/console:

NPM will automagically reference the binary in node_modules for you, andexecute the file or command.

The Result

Either method will start a server instance and begin listening for connectionsfrom localhost on port 8080.

webpack-dev-server is configured by default to support live-reload of files asyou edit your assets while the server is running.

See the documentation for more use cases and options.

Browser Support

While webpack-dev-server transpiles the client (browser) scripts to an ES5state, the project only officially supports the last two versions of majorbrowsers. We simply don't have the resources to support every whackybrowser out there.

If you find a bug with an obscure / old browser, we would actively welcome aPull Request to resolve the bug.

Support

We do our best to keep Issues in the repository focused on bugs, features, andneeded modifications to the code for the module. Because of that, we ask userswith general support, 'how-to', or 'why isn't this working' questions to try oneof the other support channels that are available.

Your first-stop-shop for support for webpack-dev-server should by the excellentdocumentation for the module. If you see an opportunity for improvementof those docs, please head over to the webpack.js.org repo and open apull request.

From there, we encourage users to visit the webpack Gitter chat andtalk to the fine folks there. If your quest for answers comes up dry in chat,head over to StackOverflow and do a quick search or open a newquestion. Remember; It's always much easier to answer questions that include yourwebpack.config.js and relevant files!

If you're twitter-savvy you can tweet #webpack with your questionand someone should be able to reach out and lend a hand.

If you have discovered a 🐛, have a feature suggestion, or would like to seea modification, please feel free to create an issue on Github. Note: The issuetemplate isn't optional, so please be sure not to remove it, and please fill itout completely.

Contributing

Webpack Dev Server

We welcome your contributions! Please have a read of CONTRIBUTING.md for more information on how to get involved.

Attribution

Webpack dev server static files

Webpack Dev Server Invalid Host Header

This project is heavily inspired by peerigon/nof5.

Webpack Dev Server Cross Domain

License