Skip to content

Commit 2c9602e

Browse files
authored
docs(configuration): add devServer.server (#5644)
* docs(configuration): add `devServer.server` * docs: update
1 parent 8464279 commit 2c9602e

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

src/content/configuration/dev-server.mdx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ To pass your certificate via CLI, use the following options:
625625
npx webpack serve --http2 --https-key ./path/to/server.key --https-cert ./path/to/server.crt --https-ca ./path/to/ca.pem
626626
```
627627

628+
W> This option is deprecated in favor of [devServer.server](#devserverserver) option.
629+
628630
## devServer.https
629631

630632
`boolean` `object`
@@ -706,6 +708,8 @@ module.exports = {
706708

707709
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.
708710

711+
W> This option is deprecated in favor of [devServer.server](#devserverserver) option.
712+
709713
## devServer.headers
710714

711715
`array` `function` `object`
@@ -1407,6 +1411,125 @@ module.exports = {
14071411
};
14081412
```
14091413

1414+
## devServer.server
1415+
1416+
`'http' | 'https' | 'spdy'` `object`
1417+
1418+
<Badge text="v4.4.0+" />
1419+
1420+
Allows to set server and options (by default 'http').
1421+
1422+
**webpack.config.js**
1423+
1424+
```javascript
1425+
module.exports = {
1426+
//...
1427+
devServer: {
1428+
server: 'http',
1429+
},
1430+
};
1431+
```
1432+
1433+
Usage via the CLI:
1434+
1435+
```bash
1436+
npx webpack serve --server-type http
1437+
```
1438+
1439+
To serve over `HTTPS` with a self-signed certificate:
1440+
1441+
**webpack.config.js**
1442+
1443+
```javascript
1444+
module.exports = {
1445+
//...
1446+
devServer: {
1447+
server: 'https',
1448+
},
1449+
};
1450+
```
1451+
1452+
Usage via the CLI:
1453+
1454+
```bash
1455+
npx webpack serve --server-type https
1456+
```
1457+
1458+
To serve over `HTTP/2` using [spdy](https://www.npmjs.com/package/spdy) with a self-signed certificate:
1459+
1460+
**webpack.config.js**
1461+
1462+
```javascript
1463+
module.exports = {
1464+
//...
1465+
devServer: {
1466+
server: 'spdy',
1467+
},
1468+
};
1469+
```
1470+
1471+
Usage via the CLI:
1472+
1473+
```bash
1474+
npx webpack serve --server-type spdy
1475+
```
1476+
1477+
Use the object syntax to provide your own certificate:
1478+
1479+
**webpack.config.js**
1480+
1481+
```javascript
1482+
module.exports = {
1483+
//...
1484+
devServer: {
1485+
server: {
1486+
type: 'https',
1487+
options: {
1488+
ca: './path/to/server.pem',
1489+
pfx: './path/to/server.pfx',
1490+
key: './path/to/server.key',
1491+
cert: './path/to/server.crt',
1492+
passphrase: 'webpack-dev-server',
1493+
requestCert: true,
1494+
},
1495+
},
1496+
},
1497+
};
1498+
```
1499+
1500+
Usage via the CLI:
1501+
1502+
```bash
1503+
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
1504+
```
1505+
1506+
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:
1507+
1508+
**webpack.config.js**
1509+
1510+
```javascript
1511+
const fs = require('fs');
1512+
const path = require('path');
1513+
1514+
module.exports = {
1515+
//...
1516+
devServer: {
1517+
server: {
1518+
type: 'https',
1519+
options: {
1520+
minVersion: 'TLSv1.1',
1521+
key: fs.readFileSync(path.join(__dirname, './server.key')),
1522+
pfx: fs.readFileSync(path.join(__dirname, './server.pfx')),
1523+
cert: fs.readFileSync(path.join(__dirname, './server.crt')),
1524+
ca: fs.readFileSync(path.join(__dirname, './ca.pem')),
1525+
passphrase: 'webpack-dev-server',
1526+
requestCert: true,
1527+
},
1528+
},
1529+
},
1530+
};
1531+
```
1532+
14101533
## devServer.setupExitSignals
14111534

14121535
`boolean = true`

0 commit comments

Comments
 (0)