Skip to content

Commit

Permalink
refactor!: remove https flag (#14681)
Browse files Browse the repository at this point in the history
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
  • Loading branch information
sapphi-red and bluwy committed Oct 18, 2023
1 parent dd610b5 commit 5b65bfd
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
2 changes: 0 additions & 2 deletions docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ vite [root]
| ------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| `--host [host]` | Specify hostname (`string`) |
| `--port <port>` | Specify port (`number`) |
| `--https` | Use TLS + HTTP/2 (`boolean`) |
| `--open [path]` | Open browser on startup (`boolean \| string`) |
| `--cors` | Enable CORS (`boolean`) |
| `--strictPort` | Exit if specified port is already in use (`boolean`) |
Expand Down Expand Up @@ -115,7 +114,6 @@ vite preview [root]
| `--host [host]` | Specify hostname (`string`) |
| `--port <port>` | Specify port (`number`) |
| `--strictPort` | Exit if specified port is already in use (`boolean`) |
| `--https` | Use TLS + HTTP/2 (`boolean`) |
| `--open [path]` | Open browser on startup (`boolean \| string`) |
| `--outDir <dir>` | Output directory (default: `dist`)(`string`) |
| `-c, --config <file>` | Use specified config file (`string`) |
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ In a project where Vite is installed, you can use the `vite` binary in your npm
}
```

You can specify additional CLI options like `--port` or `--https`. For a full list of CLI options, run `npx vite --help` in your project.
You can specify additional CLI options like `--port` or `--open`. For a full list of CLI options, run `npx vite --help` in your project.

Learn more about the [Command Line Interface](./cli.md)

Expand Down
5 changes: 5 additions & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ CLI shortcuts, like `r` to restart the dev server, now require an additional `En

This change prevents Vite from swallowing and controlling OS-specific shortcuts, allowing better compatibility when combining the Vite dev server with other processes, and avoids the [previous caveats](https://github.com/vitejs/vite/pull/14342).

### Remove `--https` flag and `https: true`

`--https` flag sets `https: true`. This config was meant to be used together with the automatic https certification generation feature which [was dropped in Vite 3](https://v3.vitejs.dev/guide/migration.html#automatic-https-certificate-generation). This config no longer makes sense as it will make Vite start a HTTPS server without a certificate.
Both [`@vitejs/plugin-basic-ssl`](https://github.com/vitejs/vite-plugin-basic-ssl) and [`vite-plugin-mkcert`](https://github.com/liuweiGL/vite-plugin-mkcert) sets `https` setting regardless of the `https` value, so you can just remove `--https` and `https: true`.

### Remove `resolvePackageEntry` and `resolvePackageData` APIs

The `resolvePackageEntry` and `resolvePackageData` APIs are removed as they exposed Vite's internals and blocked potential Vite 4.3 optimizations in the past. These APIs can be replaced with third-party packages, for example:
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ describe('preview config', () => {
strictPort: true,
host: true,
open: true,
https: true,
headers: {
'Cache-Control': 'no-store',
},
Expand Down Expand Up @@ -272,7 +271,6 @@ describe('preview config', () => {
strictPort: false,
open: false,
host: false,
https: false,
proxy: { '/bar': 'http://localhost:3010' },
cors: true,
})
Expand Down
4 changes: 0 additions & 4 deletions packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ cli
.alias('dev') // alias to align with the script name
.option('--host [host]', `[string] specify hostname`, { type: [convertHost] })
.option('--port <port>', `[number] specify port`)
.option('--https', `[boolean] use TLS + HTTP/2`)
.option('--open [path]', `[boolean | string] open browser on startup`)
.option('--cors', `[boolean] enable CORS`)
.option('--strictPort', `[boolean] exit if specified port is already in use`)
Expand Down Expand Up @@ -334,7 +333,6 @@ cli
.option('--host [host]', `[string] specify hostname`, { type: [convertHost] })
.option('--port <port>', `[number] specify port`)
.option('--strictPort', `[boolean] exit if specified port is already in use`)
.option('--https', `[boolean] use TLS + HTTP/2`)
.option('--open [path]', `[boolean | string] open browser on startup`)
.option('--outDir <dir>', `[string] output directory (default: dist)`)
.action(
Expand All @@ -343,7 +341,6 @@ cli
options: {
host?: string | boolean
port?: number
https?: boolean
open?: boolean | string
strictPort?: boolean
outDir?: string
Expand All @@ -365,7 +362,6 @@ cli
port: options.port,
strictPort: options.strictPort,
host: options.host,
https: options.https,
open: options.open,
},
})
Expand Down
6 changes: 2 additions & 4 deletions packages/vite/src/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
import type { ServerOptions as HttpsServerOptions } from 'node:https'
import type { Connect } from 'dep-types/connect'
import colors from 'picocolors'
import { isObject } from './utils'
import type { ProxyOptions } from './server/middlewares/proxy'
import type { Logger } from './logger'

Expand All @@ -31,7 +30,7 @@ export interface CommonServerOptions {
* Enable TLS + HTTP/2.
* Note: this downgrades to TLS only when the proxy option is also used.
*/
https?: boolean | HttpsServerOptions
https?: HttpsServerOptions
/**
* Open browser window on startup
*/
Expand Down Expand Up @@ -121,10 +120,9 @@ export async function resolveHttpServer(
}

export async function resolveHttpsConfig(
https: boolean | HttpsServerOptions | undefined,
https: HttpsServerOptions | undefined,
): Promise<HttpsServerOptions | undefined> {
if (!https) return undefined
if (!isObject(https)) return {}

const [ca, cert, key, pfx] = await Promise.all([
readFileIfExists(https.ca),
Expand Down

0 comments on commit 5b65bfd

Please sign in to comment.