From 2c9602e1881885950673c47e2f8e243f121b99c1 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 30 Oct 2021 21:31:12 -0700 Subject: [PATCH] docs(configuration): add `devServer.server` (#5644) * docs(configuration): add `devServer.server` * docs: update --- src/content/configuration/dev-server.mdx | 123 +++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/src/content/configuration/dev-server.mdx b/src/content/configuration/dev-server.mdx index c301599bcff2..c8bf546c0339 100644 --- a/src/content/configuration/dev-server.mdx +++ b/src/content/configuration/dev-server.mdx @@ -625,6 +625,8 @@ To pass your certificate via CLI, use the following options: npx webpack serve --http2 --https-key ./path/to/server.key --https-cert ./path/to/server.crt --https-ca ./path/to/ca.pem ``` +W> This option is deprecated in favor of [devServer.server](#devserverserver) option. + ## devServer.https `boolean` `object` @@ -706,6 +708,8 @@ module.exports = { W> Don't specify `https.ca` and `https.cacert` options together, if specified `https.ca` will be used. `https.cacert` is deprecated and will be removed in the next major release. +W> This option is deprecated in favor of [devServer.server](#devserverserver) option. + ## devServer.headers `array` `function` `object` @@ -1407,6 +1411,125 @@ module.exports = { }; ``` +## devServer.server + +`'http' | 'https' | 'spdy'` `object` + + + +Allows to set server and options (by default 'http'). + +**webpack.config.js** + +```javascript +module.exports = { + //... + devServer: { + server: 'http', + }, +}; +``` + +Usage via the CLI: + +```bash +npx webpack serve --server-type http +``` + +To serve over `HTTPS` with a self-signed certificate: + +**webpack.config.js** + +```javascript +module.exports = { + //... + devServer: { + server: 'https', + }, +}; +``` + +Usage via the CLI: + +```bash +npx webpack serve --server-type https +``` + +To serve over `HTTP/2` using [spdy](https://www.npmjs.com/package/spdy) with a self-signed certificate: + +**webpack.config.js** + +```javascript +module.exports = { + //... + devServer: { + server: 'spdy', + }, +}; +``` + +Usage via the CLI: + +```bash +npx webpack serve --server-type spdy +``` + +Use the object syntax to provide your own certificate: + +**webpack.config.js** + +```javascript +module.exports = { + //... + devServer: { + server: { + type: 'https', + options: { + ca: './path/to/server.pem', + pfx: './path/to/server.pfx', + key: './path/to/server.key', + cert: './path/to/server.crt', + passphrase: 'webpack-dev-server', + requestCert: true, + }, + }, + }, +}; +``` + +Usage via the CLI: + +```bash +npx webpack serve --server-type https --server-options-key ./path/to/server.key --server-options-cert ./path/to/server.crt --server-options-ca ./path/to/ca.pem --server-options-passphrase webpack-dev-server +``` + +It also allows you to set additional [TLS options](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) like `minVersion` and you can directly pass the contents of respective files: + +**webpack.config.js** + +```javascript +const fs = require('fs'); +const path = require('path'); + +module.exports = { + //... + devServer: { + server: { + type: 'https', + options: { + minVersion: 'TLSv1.1', + key: fs.readFileSync(path.join(__dirname, './server.key')), + pfx: fs.readFileSync(path.join(__dirname, './server.pfx')), + cert: fs.readFileSync(path.join(__dirname, './server.crt')), + ca: fs.readFileSync(path.join(__dirname, './ca.pem')), + passphrase: 'webpack-dev-server', + requestCert: true, + }, + }, + }, +}; +``` + ## devServer.setupExitSignals `boolean = true`