Webpack Dev Server

Posted onby
  • 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).
  • Webpack-dev-server does not watch for my file changes. Serve public static files with webpack.
  • Under the hood, Webpack dev server is a mini Node.js Express server. It uses a library called SockJS to emulate a web socket. The Node.js server listens to when files were changed, and triggers events to react accordingly. Webpack dev server is also a separate package that needs to get install via NPM.
Dev

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

Npm -save-dev install webpack webpack-cli webpack-dev-server html-webpack-plugin @babel/cli @babel/core @babel/polyfill @babel/preset-env @babel/preset-react babel-loader sass-loader style-loader css-loader uglifyjs-webpack-plugin. Now itโ€™s time to set up the WebPack config files. I like having a prod config file and a dev config file. Now, let's modify our npm scripts to use the new configuration files. For the start script, which runs webpack-dev-server, we will use webpack.dev.js, and for the build script, which runs webpack to create a production build, we will use webpack.prod.js: package.json.

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

Cannot

Table of Contents

  • Usage

Getting Started

First things first, install the module:

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.

Webpack Dev Server

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

Webpack dev server cors

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.

Webpack Dev Server Cors

Contributing

Webpack Dev Server Publicpath

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

Attribution

Webpack Dev Server Port Auto Change

This project is heavily inspired by peerigon/nof5.

Webpack-dev-server: Command Not Found

License