UNPKG

17.4 kBMarkdownView Raw
1<div align="center">
2 <a href="https://github.com/webpack/webpack">
3 <img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
4 </a>
5</div>
6
7[![npm][npm]][npm-url]
8[![node][node]][node-url]
9[![tests][tests]][tests-url]
10[![coverage][cover]][cover-url]
11[![chat][chat]][chat-url]
12[![downloads][downloads]][npm-url]
13[![contributors][contributors]][contributors-url]
14
15# webpack-dev-server
16
17Use [webpack](https://webpack.js.org) with a development server that provides
18live reloading. This should be used for **development only**.
19
20It uses [webpack-dev-middleware][middleware-url] under the hood, which provides
21fast in-memory access to the webpack assets.
22
23## Table of Contents
24
25- [Getting Started](#getting-started)
26- [Usage](#usage)
27 - [With the CLI](#with-the-cli)
28 - [With NPM Scripts](#with-npm-scripts)
29 - [The Result](#the-result)
30- [Browser Support](#browser-support)
31- [Support](#support)
32- [Contributing](#contributing)
33- [Attribution](#attribution)
34- [License](#license)
35
36## Getting Started
37
38First things first, install the module:
39
40```console
41npm install webpack-dev-server --save-dev
42```
43
44_Note: While you can install and run webpack-dev-server globally, we recommend
45installing it locally. webpack-dev-server will always use a local installation
46over a global one._
47
48## Usage
49
50There are two main, recommended methods of using the module:
51
52### With the CLI
53
54The easiest way to use it is with the [webpack CLI](https://webpack.js.org/api/cli/). In the directory where your
55`webpack.config.js` is, run:
56
57```console
58npx webpack serve
59```
60
61Following options are available with `webpack serve`:
62
63```
64Usage: webpack serve|server|s [entries...] [options]
65
66Run the webpack dev server.
67
68Options:
69 -c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
70 --config-name <value...> Name of the configuration to use.
71 -m, --merge Merge two or more configurations using 'webpack-merge'.
72 --env <value...> Environment passed to the configuration when it is a function.
73 --node-env <value> Sets process.env.NODE_ENV to the specified value.
74 --progress [value] Print compilation progress during build.
75 -j, --json [value] Prints result as JSON or store it in a file.
76 --entry <value...> The entry point(s) of your application e.g. ./src/main.js.
77 -o, --output-path <value> Output location of the file generated by webpack e.g. ./dist/.
78 -t, --target <value> Sets the build target e.g. node.
79 -d, --devtool <value> Determine source maps to use.
80 --no-devtool Do not generate source maps.
81 --mode <value> Defines the mode to pass to webpack.
82 --name <value> Name of the configuration. Used when loading multiple configurations.
83 --stats [value] It instructs webpack on how to treat the stats e.g. verbose.
84 --no-stats Disable stats output.
85 --watch-options-stdin Stop watching when stdin stream has ended.
86 --no-watch-options-stdin Do not stop watching when stdin stream has ended.
87 --allowed-hosts <value...> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').
88 --allowed-hosts-reset Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').
89 --bonjour Allows to broadcasts dev server via ZeroConf networking on start.
90 --no-bonjour Disallows to broadcasts dev server via ZeroConf networking on start.
91 --client-web-socket-transport <value> Allows to set custom web socket transport to communicate with dev server.
92 --no-client Negative 'client' option.
93 --client-logging <value> Allows to specify options for client script in the browser or disable client script.
94 --client-progress Prints compilation progress in percentage in the browser.
95 --no-client-progress Does not print compilation progress in percentage in the browser.
96 --client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings.
97 --no-client-overlay Disables a full-screen overlay in the browser when there are compiler errors or warnings.
98 --client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors.
99 --no-client-overlay-errors Negative 'client-overlay-errors' option.
100 --client-overlay-warnings Enables a full-screen overlay in the browser when there are compiler warnings.
101 --no-client-overlay-warnings Negative 'client-overlay-warnings' option.
102 --client-web-socket-url <value> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
103 --client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
104 --client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
105 --client-web-socket-url-pathname <value> Tells clients connected to devServer to use the provided path to connect.
106 --client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
107 --client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
108 --client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
109 --web-socket-server <value> Allows to set web socket server and options (by default 'ws').
110 --no-web-socket-server Negative 'web-socket-server' option.
111 --compress Enables gzip compression for everything served.
112 --no-compress Disables gzip compression for everything served.
113 --history-api-fallback Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API.
114 --no-history-api-fallback Negative 'history-api-fallback' option.
115 --host <value> Allows to specify a hostname to use.
116 --hot [value] Enables Hot Module Replacement.
117 --no-hot Disables Hot Module Replacement.
118 --http2 Allows to serve over HTTP/2 using SPDY.
119 --no-http2 Does not serve over HTTP/2 using SPDY.
120 --https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).
121 --no-https Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).
122 --https-passphrase <value> Passphrase for a pfx file.
123 --https-request-cert Request for an SSL certificate.
124 --no-https-request-cert Does not request for an SSL certificate.
125 --https-ca <value...> Path to an SSL CA certificate or content of an SSL CA certificate.
126 --https-ca-reset Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.
127 --https-cacert <value...> Path to an SSL CA certificate or content of an SSL CA certificate.
128 --https-cacert-reset Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.
129 --https-key <value...> Path to an SSL key or content of an SSL key.
130 --https-key-reset Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key.
131 --https-pfx <value...> Path to an SSL pfx file or content of an SSL pfx file.
132 --https-pfx-reset Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file.
133 --https-cert <value...> Path to an SSL certificate or content of an SSL certificate.
134 --https-cert-reset Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate.
135 --https-crl <value...> Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).
136 --https-crl-reset Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).
137 --ipc [value] Listen to a unix socket.
138 --live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
139 --no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default)
140 --magic-html Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').
141 --no-magic-html Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').
142 --open [value...] Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).
143 --no-open Does not open the default browser.
144 --open-target <value...> Opens specified page in browser.
145 --open-app-name <value...> Open specified browser.
146 --open-app <value...> Open specified browser.
147 --open-reset Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).
148 --open-target-reset Clear all items provided in 'open.target' configuration. Opens specified page in browser.
149 --open-app-name-reset Clear all items provided in 'open.app.name' configuration. Open specified browser.
150 --port <value> Allows to specify a port to use.
151 --static [value...] Allows to configure options for serving static files from directory (by default 'public' directory).
152 --no-static Negative 'static' option.
153 --static-directory <value...> Directory for static contents.
154 --static-public-path <value...> The static files will be available in the browser under this public path.
155 --static-serve-index Tells dev server to use serveIndex middleware when enabled.
156 --no-static-serve-index Does not tell dev server to use serveIndex middleware.
157 --static-watch Watches for files in static content directory.
158 --no-static-watch Does not watch for files in static content directory.
159 --static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory).
160 --static-public-path-reset Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.
161 --watch-files <value...> Allows to configure list of globs/directories/files to watch for file changes.
162 --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.
163
164Global options:
165 --color Enable colors on console.
166 --no-color Disable colors on console.
167 -v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
168 -h, --help [verbose] Display help for commands and options.
169
170To see list of all supported commands and options run 'webpack --help=verbose'.
171
172Webpack documentation: https://webpack.js.org/.
173CLI documentation: https://webpack.js.org/api/cli/.
174Made with ♥ by the webpack team.
175```
176
177_**Note**: For more information on above options explore this [link](https://webpack.js.org/configuration/dev-server/)._
178
179### With NPM Scripts
180
181NPM package.json scripts are a convenient and useful means to run locally installed
182binaries without having to be concerned about their full paths. Simply define a
183script as such:
184
185```json
186{
187 "scripts": {
188 "serve": "webpack serve"
189 }
190}
191```
192
193And run the following in your terminal/console:
194
195```console
196npm run serve
197```
198
199NPM will automagically reference the binary in `node_modules` for you, and
200execute the file or command.
201
202### The Result
203
204Either method will start a server instance and begin listening for connections
205from `localhost` on port `8080`.
206
207webpack-dev-server is configured by default to support live-reload of files as
208you edit your assets while the server is running.
209
210See [**the documentation**][docs-url] for more use cases and options.
211
212## Browser Support
213
214While `webpack-dev-server` transpiles the client (browser) scripts to an ES5
215state, the project only officially supports the _last two versions of major
216browsers_. We simply don't have the resources to support every whacky
217browser out there.
218
219If you find a bug with an obscure / old browser, we would actively welcome a
220Pull Request to resolve the bug.
221
222## Support
223
224We do our best to keep Issues in the repository focused on bugs, features, and
225needed modifications to the code for the module. Because of that, we ask users
226with general support, "how-to", or "why isn't this working" questions to try one
227of the other support channels that are available.
228
229Your first-stop-shop for support for webpack-dev-server should be the excellent
230[documentation][docs-url] for the module. If you see an opportunity for improvement
231of those docs, please head over to the [webpack.js.org repo][wjo-url] and open a
232pull request.
233
234From there, we encourage users to visit the [webpack Gitter chat][chat-url] and
235talk to the fine folks there. If your quest for answers comes up dry in chat,
236head over to [StackOverflow][stack-url] and do a quick search or open a new
237question. Remember; It's always much easier to answer questions that include your
238`webpack.config.js` and relevant files!
239
240If you're twitter-savvy you can tweet [#webpack][hash-url] with your question
241and someone should be able to reach out and lend a hand.
242
243If you have discovered a :bug:, have a feature suggestion, or would like to see
244a modification, please feel free to create an issue on Github. _Note: The issue
245template isn't optional, so please be sure not to remove it, and please fill it
246out completely._
247
248## Contributing
249
250We welcome your contributions! Please have a read of [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to get involved.
251
252## Attribution
253
254This project is heavily inspired by [peerigon/nof5](https://github.com/peerigon/nof5).
255
256## License
257
258#### [MIT](./LICENSE)
259
260[npm]: https://img.shields.io/npm/v/webpack-dev-server.svg
261[npm-url]: https://npmjs.com/package/webpack-dev-server
262[node]: https://img.shields.io/node/v/webpack-dev-server.svg
263[node-url]: https://nodejs.org
264[tests]: https://github.com/webpack/webpack-dev-server/workflows/webpack-dev-server/badge.svg
265[tests-url]: https://github.com/webpack/webpack-dev-server/actions?query=workflow%3Awebpack-dev-server
266[cover]: https://codecov.io/gh/webpack/webpack-dev-server/branch/master/graph/badge.svg
267[cover-url]: https://codecov.io/gh/webpack/webpack-dev-server
268[chat]: https://badges.gitter.im/webpack/webpack.svg
269[chat-url]: https://gitter.im/webpack/webpack
270[docs-url]: https://webpack.js.org/configuration/dev-server/#devserver
271[hash-url]: https://twitter.com/search?q=webpack
272[middleware-url]: https://github.com/webpack/webpack-dev-middleware
273[stack-url]: https://stackoverflow.com/questions/tagged/webpack-dev-server
274[uglify-url]: https://github.com/webpack-contrib/uglifyjs-webpack-plugin
275[wjo-url]: https://github.com/webpack/webpack.js.org
276[downloads]: https://img.shields.io/npm/dm/webpack-dev-server.svg
277[contributors-url]: https://github.com/webpack/webpack-dev-server/graphs/contributors
278[contributors]: https://img.shields.io/github/contributors/webpack/webpack-dev-server.svg