Skip to content

Commit 75f118a

Browse files
(release): v2.6.14
2 parents c2a6b72 + 72ea75c commit 75f118a

17 files changed

+299
-64
lines changed

.vitepress/theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
Layout() {
1010
return h(Theme.Layout, null, {
1111
'sidebar-bottom': () =>
12-
h('div', { class: 'sponsors' }, [
12+
h('div', { class: 'sponsors sidebar' }, [
1313
h(
1414
'a',
1515
{

.vitepress/theme/sponsors.css

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
.sponsors a {
77
color: #999;
8+
margin: 1em;
9+
display: block;
810
}
911

1012
.sponsors img {
11-
max-width: 200px;
12-
height: 40px;
13-
display: block;
14-
margin: 1.25rem 0;
13+
max-width: 160px;
14+
max-height: 40px;
1515
}
1616

1717
.sponsors.frontpage {
@@ -21,7 +21,6 @@
2121
.sponsors.frontpage img {
2222
display: inline-block;
2323
vertical-align: middle;
24-
margin: 0 1rem 1.25rem 1rem;
2524
}
2625

2726
.sponsors.frontpage h2 {
@@ -30,7 +29,28 @@
3029
border: none;
3130
}
3231

32+
.sponsors.sidebar a img {
33+
max-height: 36px;
34+
}
35+
36+
.platinum-sponsors {
37+
margin-bottom: 1.5em;
38+
}
39+
40+
.platinum-sponsors a img {
41+
max-width: 240px;
42+
max-height: 60px;
43+
}
44+
45+
.gold-sponsors {
46+
display: flex;
47+
flex-wrap: wrap;
48+
justify-content: space-evenly;
49+
align-items: center;
50+
}
51+
3352
/* special cases */
3453
#sponsor-mux {
3554
padding: 5px 0;
55+
min-height: 36px;
3656
}

.vitepress/theme/sponsors.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
[
2+
{
3+
"id": "stackblitz",
4+
"name": "StackBlitz",
5+
"href": "https://stackblitz.com/",
6+
"src": "/stackblitz.svg",
7+
"tier": "platinum"
8+
},
29
{
310
"id": "tailwind",
411
"name": "Tailwind Labs",
@@ -22,5 +29,11 @@
2229
"name": "Plaid Inc.",
2330
"href": "https://plaid.co.jp/",
2431
"src": "/plaid.svg"
32+
},
33+
{
34+
"id": "divriots",
35+
"name": "divriots",
36+
"href": "https://divriots.com/",
37+
"src": "/divriots.png"
2538
}
2639
]

config/index.md

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ Vite 也直接支持 TS 配置文件。你可以在 `vite.config.ts` 中使用 `
5252

5353
### 情景配置 {#conditional-config}
5454

55-
如果配置文件需要基于(`serve``build`)命令或者不同的 [模式](/guide/env-and-mode) 来决定选项,则可以选择导出这样一个函数:
55+
如果配置文件需要基于(`dev`/`serve``build`)命令或者不同的 [模式](/guide/env-and-mode) 来决定选项,则可以选择导出这样一个函数:
5656

5757
```js
5858
export default defineConfig(({ command, mode }) => {
5959
if (command === 'serve') {
6060
return {
61-
// serve 独有配置
61+
// dev 独有配置
6262
}
6363
} else {
64+
// command === 'build'
6465
return {
6566
// build 独有配置
6667
}
6768
}
6869
})
6970
```
7071

72+
需要注意的是,在 Vite 的 API 中,在开发环境下 `command` 的值为 `serve`(在 CLI 中, `vite dev``vite serve``vite` 的别名),而在生产环境下为 `build``vite build`)。
73+
7174
### 异步配置 {#async-config}
7275

7376
如果配置需要调用一个异步函数,也可以转而导出一个异步函数:
@@ -169,7 +172,12 @@ export default defineConfig(async ({ command, mode }) => {
169172

170173
如果你在你的应用程序中有相同依赖的副本(比如 monorepos),请使用此选项强制 Vite 始终将列出的依赖项解析为同一副本(从项目根目录)。
171174

172-
### resolve.conditions {#resolve-conditions}
175+
:::warning SSR + ESM
176+
对于服务端渲染构建,配置项 `build.rollupOptions.output` 为 ESM 构建输出时去重过程将不工作。一个替代方案是先使用 CJS 构建输出,直到 ESM 在插件中有了更好的模块加载支持。
177+
:::
178+
179+
### resolve.conditions
180+
173181

174182
- **类型:** `string[]`
175183

@@ -356,20 +364,19 @@ export default defineConfig(async ({ command, mode }) => {
356364

357365
`envPrefix` 开头的环境变量会通过 import.meta.env 暴露在你的客户端源码中。
358366

359-
:::warning 安全注意事项
360-
361-
- `envPrefix` 不应该被设置为 `''`,因为这将暴露你所有的环境变量,导致敏感信息的意外泄露。Vite 在检测到 `''` 时将会抛出错误。
367+
:::warning 安全注意事项
368+
`envPrefix` 不应被设置为空字符串 `''`,这将暴露你所有的环境变量,导致敏感信息的意外泄漏。 检测到配置为 `''` 时 Vite 将会抛出错误.
362369
:::
363370

364371
## 开发服务器选项 {#server-options}
365372

366373
### server.host {#server-host}
367374

368-
- **类型:** `string`
375+
- **类型:** `string | boolean`
369376
- **默认:** `'127.0.0.1'`
370377

371378
指定服务器应该监听哪个 IP 地址。
372-
如果将此设置为 `0.0.0.0` 将监听所有地址,包括局域网和公网地址。
379+
如果将此设置为 `0.0.0.0` 或者 `true` 将监听所有地址,包括局域网和公网地址。
373380

374381
也可以通过 CLI 使用 `--host 0.0.0.0``--host` 来设置。
375382

@@ -540,15 +547,13 @@ createServer()
540547

541548
### server.fs.strict {#server-fs-strict}
542549

543-
- **实验性**
544550
- **类型:** `boolean`
545-
- **默认:** `false` (将在后续版本中改为 `true`)
551+
- **默认:** `true` (自 Vite 2.7 起默认启用)
546552

547553
限制为工作区 root 路径以外的文件的访问。
548554

549555
### server.fs.allow {#server-fs-allow}
550556

551-
- **实验性**
552557
- **类型:** `string[]`
553558

554559
限制哪些文件可以通过 `/@fs/` 路径提供服务。当 `server.fs.strict` 设置为 true 时,访问这个目录列表外的文件将会返回 403 结果。
@@ -591,6 +596,15 @@ createServer()
591596
})
592597
```
593598

599+
### server.fs.deny {#server-fs-deny}
600+
601+
- **实验性**
602+
- **类型:** `string[]`
603+
604+
用于限制 Vite 开发服务器提供敏感文件的黑名单。
605+
606+
默认为 `['.env', '.env.*', '*.{pem,crt}']`
607+
594608
### server.origin {#server-origin}
595609

596610
- **类型:** `string`
@@ -673,7 +687,11 @@ export default defineConfig({
673687

674688
如果禁用,整个项目中的所有 CSS 将被提取到一个 CSS 文件中。
675689

676-
### build.cssTarget {#build-csstarget}
690+
::: tip 注意
691+
如果指定了 `build.lib``build.cssCodeSplit` 会默认为 `false`
692+
:::
693+
694+
### build.cssTarget
677695

678696
- **类型:** `string | string[]`
679697
- **默认值:**[`build.target`](/config/#build-target) 一致
@@ -732,6 +750,14 @@ export default defineConfig({
732750

733751
当设置为 `true` 时,构建也将生成 SSR 的 manifest 文件,以确定生产中的样式链接与资产预加载指令。
734752

753+
### build.ssr {#build-ssr}
754+
755+
- **类型:** `boolean | string`
756+
- **默认值:** `undefined`
757+
- **相关链接:** [Server-Side Rendering](/guide/ssr)
758+
759+
生成面向 SSR 的构建。此选项的值可以是字符串,用于直接定义 SSR 的入口,也可以为 `true`,但这需要通过设置 `rollupOptions.input` 来指定 SSR 的入口。
760+
735761
### build.minify {#build-minify}
736762

737763
- **类型:** `boolean | 'terser' | 'esbuild'`
@@ -780,6 +806,77 @@ export default defineConfig({
780806

781807
设置为 `{}` 则会启用 rollup 的监听器。在涉及只用在构建时的插件时和集成开发流程中很常用。
782808

809+
## 预览选项 {#preview-options}
810+
811+
### preview.host {#preview-host}
812+
813+
- **类型:** `string | boolean`
814+
- **默认:** [`server.host`](#server_host)
815+
816+
为开发服务器指定 ip 地址。
817+
设置为 `0.0.0.0``true` 会监听所有地址,包括局域网和公共地址。
818+
819+
还可以通过 CLI 进行设置,使用 `--host 0.0.0.0``--host`
820+
821+
### preview.port {#preview-port}
822+
823+
- **类型:** `number`
824+
- **默认:** `5000`
825+
826+
指定开发服务器端口。注意,如果设置的端口已被使用,Vite 将自动尝试下一个可用端口,所以这可能不是最终监听的服务器端口。
827+
828+
**示例:**
829+
830+
```js
831+
export default defineConfig({
832+
server: {
833+
port: 3030
834+
},
835+
preview: {
836+
port: 8080
837+
}
838+
})
839+
```
840+
841+
### preview.strictPort {#preview-strictport}
842+
843+
- **类型:** `boolean`
844+
- **默认:** [`server.strictPort`](#server_strictport)
845+
846+
设置为 `true` 时,如果端口已被使用,则直接退出,而不会再进行后续端口的尝试。
847+
848+
### preview.https {#preview-https}
849+
850+
- **类型:** `boolean | https.ServerOptions`
851+
- **默认:** [`server.https`](#server_https)
852+
853+
启用 TLS + HTTP/2。注意,只有在与 [`server.proxy` 选项](#server-proxy) 同时使用时,才会降级为 TLS。
854+
855+
该值也可以传递给 `https.createServer()`[options 对象](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener)
856+
857+
### preview.open {#preview-open}
858+
859+
- **类型:** `boolean | string`
860+
- **默认:** [`server.open`](#server_open)
861+
862+
开发服务器启动时,自动在浏览器中打开应用程序。当该值为字符串时,它将被用作 URL 的路径名。如果你想在你喜欢的某个浏览器打开该开发服务器,你可以设置环境变量 `process.env.BROWSER` (例如 `firefox`)。欲了解更多细节,请参阅 [`open` 包的源码](https://github.com/sindresorhus/open#app)
863+
864+
### preview.proxy {#preview-proxy}
865+
866+
- **类型:** `Record<string, string | ProxyOptions>`
867+
- **默认:** [`server.proxy`](#server_proxy)
868+
869+
为开发服务器配置自定义代理规则。其值的结构为 `{ key: options }` 的对象。如果 key 以 `^` 开头,它将被识别为 `RegExp`,其中 `configure` 选项可用于访问代理实例。
870+
871+
基于 [`http-proxy`](https://github.com/http-party/node-http-proxy) 实现,完整的参数列表参见 [此链接](https://github.com/http-party/node-http-proxy#options)
872+
873+
### preview.cors {#preview-cors}
874+
875+
- **类型:** `boolean | CorsOptions`
876+
- **默认:** [`server.cors`](#server_proxy)
877+
878+
为开发服务器配置 CORS。此功能默认启用,支持任何来源。可传递一个 [options 对象](https://github.com/expressjs/cors) 来进行配置,或者传递 `false` 来禁用此行为。
879+
783880
## 依赖优化选项 {#dep-optimization-options}
784881

785882
- **相关内容:** [依赖预构建](/guide/dep-pre-bundling)

guide/api-hmr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ImportMeta {
1818
accept(dep: string, cb: (mod: any) => void): void
1919
accept(deps: string[], cb: (mods: any[]) => void): void
2020

21+
prune(cb: () => void): void
2122
dispose(cb: (data: any) => void): void
2223
decline(): void
2324
invalidate(): void

guide/api-javascript.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const { createServer } = require('vite')
2525
}
2626
})
2727
await server.listen()
28+
29+
server.printUrls()
2830
})()
2931
```
3032

@@ -35,7 +37,7 @@ const { createServer } = require('vite')
3537
- `configFile`:指明要使用的配置文件。如果没有设置,Vite 将尝试从项目根目录自动解析。设置为 `false` 可以禁用自动解析功能。
3638
- `envFile`:设置为 `false` 时,则禁用 `.env` 文件。
3739

38-
## `ViteDevServer`
40+
## `ViteDevServer` {#vitedevserver}
3941

4042
```ts
4143
interface ViteDevServer {
@@ -100,14 +102,20 @@ interface ViteDevServer {
100102
* 启动服务器
101103
*/
102104
listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>
105+
/**
106+
* 重启服务器
107+
*
108+
* @param forceOptimize - 强制优化器重新大伯啊,和命令行内使用 --force 一致
109+
*/
110+
restart(forceOptimize?: boolean): Promise<void>
103111
/**
104112
* 停止服务器
105113
*/
106114
close(): Promise<void>
107115
}
108116
```
109117

110-
## `build`
118+
## `build` {#build}
111119

112120
**类型校验:**
113121

@@ -126,8 +134,8 @@ const { build } = require('vite')
126134
;(async () => {
127135
await build({
128136
root: path.resolve(__dirname, './project'),
137+
base: '/foo/',
129138
build: {
130-
base: '/foo/',
131139
rollupOptions: {
132140
// ...
133141
}
@@ -136,6 +144,34 @@ const { build } = require('vite')
136144
})()
137145
```
138146

147+
## `preview` {#preview}
148+
149+
**实验阶段**
150+
151+
**类型签名:**
152+
153+
```ts
154+
async function preview(inlineConfig?: InlineConfig): Promise<PreviewServer>
155+
```
156+
157+
**示例用法:**
158+
159+
```js
160+
const { preview } = require('vite')
161+
162+
;(async () => {
163+
const previewServer = await preview({
164+
// 任何有效的用户配置项,将加上 `mode``configFile`
165+
preview: {
166+
port: 8080,
167+
open: true
168+
}
169+
})
170+
171+
previewServer.printUrls()
172+
})()
173+
```
174+
139175
## `resolveConfig` {#resolveconfig}
140176

141177
**类型校验:**
@@ -148,6 +184,8 @@ async function resolveConfig(
148184
): Promise<ResolvedConfig>
149185
```
150186

187+
The `command` value is `serve` in dev (in the cli `vite`, `vite dev`, and `vite serve` are aliases).
188+
151189
## `transformWithEsbuild`
152190

153191
**类型签名:**

0 commit comments

Comments
 (0)