From 5b65bfdb4808660f63fcca15cbeea0fde1ae5b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 19 Oct 2023 03:09:13 +0900 Subject: [PATCH] refactor!: remove https flag (#14681) Co-authored-by: Bjorn Lu --- docs/guide/cli.md | 2 -- docs/guide/index.md | 2 +- docs/guide/migration.md | 5 +++++ packages/vite/src/node/__tests__/config.spec.ts | 2 -- packages/vite/src/node/cli.ts | 4 ---- packages/vite/src/node/http.ts | 6 ++---- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/docs/guide/cli.md b/docs/guide/cli.md index a2650d63018d32..08134c4c839a8b 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -18,7 +18,6 @@ vite [root] | ------------------------ | ------------------------------------------------------------------------------------------------------------------ | | `--host [host]` | Specify hostname (`string`) | | `--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`) | @@ -115,7 +114,6 @@ vite preview [root] | `--host [host]` | Specify hostname (`string`) | | `--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 ` | Output directory (default: `dist`)(`string`) | | `-c, --config ` | Use specified config file (`string`) | diff --git a/docs/guide/index.md b/docs/guide/index.md index af5ab30e410f77..6b21c00d28ea77 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -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) diff --git a/docs/guide/migration.md b/docs/guide/migration.md index fc30edc3b6ede1..3a979b566cfd37 100644 --- a/docs/guide/migration.md +++ b/docs/guide/migration.md @@ -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: diff --git a/packages/vite/src/node/__tests__/config.spec.ts b/packages/vite/src/node/__tests__/config.spec.ts index b4196af570d207..3d5728f86cea4f 100644 --- a/packages/vite/src/node/__tests__/config.spec.ts +++ b/packages/vite/src/node/__tests__/config.spec.ts @@ -232,7 +232,6 @@ describe('preview config', () => { strictPort: true, host: true, open: true, - https: true, headers: { 'Cache-Control': 'no-store', }, @@ -272,7 +271,6 @@ describe('preview config', () => { strictPort: false, open: false, host: false, - https: false, proxy: { '/bar': 'http://localhost:3010' }, cors: true, }) diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 12538bb9adb270..02e9ff3b6ea473 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -139,7 +139,6 @@ cli .alias('dev') // alias to align with the script name .option('--host [host]', `[string] specify hostname`, { type: [convertHost] }) .option('--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`) @@ -334,7 +333,6 @@ cli .option('--host [host]', `[string] specify hostname`, { type: [convertHost] }) .option('--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 ', `[string] output directory (default: dist)`) .action( @@ -343,7 +341,6 @@ cli options: { host?: string | boolean port?: number - https?: boolean open?: boolean | string strictPort?: boolean outDir?: string @@ -365,7 +362,6 @@ cli port: options.port, strictPort: options.strictPort, host: options.host, - https: options.https, open: options.open, }, }) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index afefc14fc5e1d0..579b995c9ae92d 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -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' @@ -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 */ @@ -121,10 +120,9 @@ export async function resolveHttpServer( } export async function resolveHttpsConfig( - https: boolean | HttpsServerOptions | undefined, + https: HttpsServerOptions | undefined, ): Promise { if (!https) return undefined - if (!isObject(https)) return {} const [ca, cert, key, pfx] = await Promise.all([ readFileIfExists(https.ca),