dev.https

  • Type: boolean | { key: string; cert: string }
  • Default: false

After configuring this option, you can enable HTTPS Dev Server, and disabling the HTTP Dev Server.

HTTP:

> Local: http://localhost:8080/
  > Network: http://192.168.0.1:8080/

HTTPS:

> Local: https://localhost:8080/
  > Network: https://192.168.0.1:8080/

Automatically generate certificates

You can directly set https to true, Builder will automatically generate the HTTPS certificate based on devcert.

When using this method, you need to manually install the devcert dependency in your project:

# npm
npm install devcert@1.2.2 -D

# yarn
yarn add devcert@1.2.2 -D

# pnpm
pnpm add devcert@1.2.2 -D

Then configure dev.https to true:

export default {
  dev: {
    https: true,
  },
};

The devcert has some limitations, it does not currently support IP addresses yet.

TIP

The https proxy automatically installs the certificate and needs root authority, please enter the password according to the prompt.The password is only used to trust the certificate, and will not be leaked or be used elsewhere.

Manually set the certificate

You can also manually pass in the certificate and the private key required in the dev.https option. This parameter will be directly passed to the createServer method of the https module in Node.js.

For details, please refer to https.createServer.

import fs from 'fs';

export default {
  dev: {
    https: {
      key: fs.readFileSync('certificates/private.pem'),
      cert: fs.readFileSync('certificates/public.pem'),
    },
  },
};