Skip to content

Commit 717f162

Browse files
authored
docs(cn): update with mainstream
2 parents 50e8c6b + 9f83a65 commit 717f162

23 files changed

+427
-249
lines changed

.vitepress/config.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineConfig({
3939
ja: { label: '日本語', link: 'https://ja.vitejs.dev' },
4040
es: { label: 'Español', link: 'https://es.vitejs.dev' },
4141
pt: { label: 'Português', link: 'https://pt.vitejs.dev' },
42+
ko: { label: '한국어', link: 'https://ko.vitejs.dev' },
4243
},
4344

4445
themeConfig: {
@@ -228,11 +229,15 @@ export default defineConfig({
228229
text: '故障排除',
229230
link: '/guide/troubleshooting'
230231
},
232+
{
233+
text: '理念',
234+
link: '/guide/philosophy',
235+
},
231236
{
232237
text: '从 v3 迁移',
233238
link: '/guide/migration'
234-
}
235-
]
239+
},
240+
],
236241
},
237242
{
238243
text: 'API',
@@ -297,13 +302,4 @@ export default defineConfig({
297302
]
298303
}
299304
},
300-
301-
markdown: {
302-
anchor: {
303-
permalink: renderPermaLink
304-
},
305-
config: (md) => {
306-
md.use(MarkDownItCustomAnchor)
307-
}
308-
}
309305
})

.vitepress/theme/components/HomeSponsors.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ const { data } = useSponsor()
4646
text-align: center;
4747
font-weight: 600;
4848
white-space: nowrap;
49-
transition: color 0.25s, border-color 0.25s, background-color 0.25s;
49+
transition:
50+
color 0.25s,
51+
border-color 0.25s,
52+
background-color 0.25s;
5053
/* .VPButton.medium */
5154
border-radius: 20px;
5255
padding: 0 20px;

.vitepress/theme/composables/sponsor.ts

+42-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,27 @@ const data = ref()
2121
const dataHost = 'https://sponsors.vuejs.org'
2222
const dataUrl = `${dataHost}/vite.json`
2323

24-
// no sponsors yet :(
25-
const viteSponsors: Pick<Sponsors, 'gold'> = {
24+
const viteSponsors: Pick<Sponsors, 'special' | 'gold'> = {
25+
special: [
26+
// sponsors patak-dev
27+
{
28+
name: 'StackBlitz',
29+
url: 'https://stackblitz.com',
30+
img: '/stackblitz.svg',
31+
},
32+
// sponsors antfu
33+
{
34+
name: 'NuxtLabs',
35+
url: 'https://nuxtlabs.com',
36+
img: '/nuxtlabs.svg',
37+
},
38+
// sponsors bluwy
39+
{
40+
name: 'Astro',
41+
url: 'https://astro.build',
42+
img: '/astro.svg',
43+
},
44+
],
2645
gold: [],
2746
}
2847

@@ -46,7 +65,12 @@ export function useSponsor() {
4665
function mapSponsors(sponsors: Sponsors) {
4766
return [
4867
{
49-
tier: 'Platinum Sponsor',
68+
tier: 'Special Sponsors',
69+
size: 'big',
70+
items: viteSponsors['special'],
71+
},
72+
{
73+
tier: 'Platinum Sponsors',
5074
size: 'big',
5175
items: mapImgPath(sponsors['platinum']),
5276
},
@@ -58,9 +82,20 @@ function mapSponsors(sponsors: Sponsors) {
5882
]
5983
}
6084

85+
const viteSponsorNames = new Set(
86+
Object.values(viteSponsors).flatMap((sponsors) =>
87+
sponsors.map((s) => s.name),
88+
),
89+
)
90+
91+
/**
92+
* Map Vue/Vite sponsors data to objects and filter out Vite-specific sponsors
93+
*/
6194
function mapImgPath(sponsors: Sponsor[]) {
62-
return sponsors.map((sponsor) => ({
63-
...sponsor,
64-
img: `${dataHost}/images/${sponsor.img}`,
65-
}))
95+
return sponsors
96+
.filter((sponsor) => !viteSponsorNames.has(sponsor.name))
97+
.map((sponsor) => ({
98+
...sponsor,
99+
img: `${dataHost}/images/${sponsor.img}`,
100+
}))
66101
}

.vitepress/theme/styles/vars.css

+4
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,7 @@
114114
.dark .vp-doc .custom-block a {
115115
transition: color 0.25s;
116116
}
117+
118+
.vp-sponsor.aside .vp-sponsor-grid.mini .vp-sponsor-grid-image {
119+
max-width: 124px;
120+
}

config/build-options.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import 'vite/modulepreload-polyfill'
3434

3535
每个动态导入要预加载的块列表将由 Vite 计算。默认情况下,在载入这些依赖时,会使用一个包含 `base` 的绝对路径。如果 `base` 是相对路径(`''` 或者 './'),解析时则会使用 `import.meta.url`,以避免出现依赖于最终部署基路径的绝对路径。
3636

37-
目前有一个实验性功能支持使用 `resolveDependencies` 函数对依赖项列表及其路径进行细粒度控制。它期望接收一个 `ResolveModulePreloadDependenciesFn` 类型的函数:
37+
目前有一个实验性功能支持使用 `resolveDependencies` 函数对依赖项列表及其路径进行细粒度控制。可以在这里 [提供反馈](https://github.com/vitejs/vite/discussions/13841)它期望接收一个 `ResolveModulePreloadDependenciesFn` 类型的函数:
3838

3939
```ts
4040
type ResolveModulePreloadDependenciesFn = (
@@ -119,10 +119,10 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含它们所
119119
120120
## build.cssMinify {#build-cssminify}
121121
122-
- **类型:** `boolean`
122+
- **类型:** `boolean | 'esbuild' | 'lightningcss'`
123123
- **默认:** 与 [`build.minify`](#build-minify) 一致
124124
125-
此选项允许用户覆盖 CSS 最小化压缩的配置,而不是使用默认的 `build.minify`,这样你就可以单独配置 JS 和 CSS 的最小化压缩方式。Vite 使用 `esbuild` 来最小化 CSS。
125+
此选项允许用户覆盖 CSS 最小化压缩的配置,而不是使用默认的 `build.minify`,这样你就可以单独配置 JS 和 CSS 的最小化压缩方式。Vite 默认使用 `esbuild` 来最小化 CSS。将此选项设置为 `'lightningcss'` 可以改用 [Lightning CSS](https://lightningcss.dev/minification.html) 进行压缩。设置为该项,便可以使用 [`css.lightningcss`](./shared-options.md#css-lightningcss) 选项来进行配置
126126
127127
## build.sourcemap {#build-sourcemap}
128128
@@ -218,7 +218,7 @@ npm add -D terser
218218
219219
## build.copyPublicDir {#build-copypublicdir}
220220
221-
- **实验性特性**
221+
- **实验性:** [提供反馈](https://github.com/vitejs/vite/discussions/13807)
222222
- **类型:** `boolean`
223223
- **默认:** `true`
224224

config/dep-optimization-options.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ export default defineConfig({
3535

3636
默认情况下,不在 `node_modules` 中的,链接的包不会被预构建。使用此选项可强制预构建链接的包。
3737

38-
## optimizeDeps.esbuildOptions {#optimizedeps-esbuildoptions}
38+
**实验性:** 如果你使用的是一个有很多深层导入的库,你也可以指定一个尾部的 glob 模式来一次性地预构建所有深层导入。这将避免在使用新的深层导入时不断地预构建。例如:
39+
40+
```js
41+
export default defineConfig({
42+
optimizeDeps: {
43+
include: ['my-lib/components/**/*.vue'],
44+
},
45+
})
46+
```
47+
48+
## optimizeDeps.esbuildOptions {#optimizedeps-esbuild-options}
3949

4050
- **类型:** [`EsbuildBuildOptions`](https://esbuild.github.io/api/#simple-options)
4151

@@ -54,7 +64,7 @@ export default defineConfig({
5464

5565
## optimizeDeps.disabled {#optimizedeps-disabled}
5666

57-
- **实验性**
67+
- **实验性** [提供反馈](https://github.com/vitejs/vite/discussions/13839)
5868
- **类型:** `boolean | 'build' | 'dev'`
5969
- **默认:** `'build'`
6070

@@ -71,5 +81,4 @@ export default defineConfig({
7181
- **实验性**
7282
- **类型:** `string[]`
7383

74-
当导入这些依赖项时,会强制 ESM 转换。Vite 能够正确检测到依赖项是否需要转换处理(interop),因此通常不需要使用此选项。然而,不同的依赖项组合可能导致其中一些包以不同方式预构建。将这些包添加到 `needsInterop` 中可以通过避免重新加载整个页面、加快冷启动速度。如果您的某个依赖项符合此情况,Vite 将抛出警告,建议你在配置中添加该包名。
75-
84+
当导入这些依赖项时,会强制 ESM 转换。Vite 能够正确检测到依赖项是否需要转换处理(interop),因此通常不需要使用此选项。然而,不同的依赖项组合可能导致其中一些包以不同方式预构建。将这些包添加到 `needsInterop` 中可以通过避免重新加载整个页面、加快冷启动速度。如果某个依赖项符合此情况,Vite 将抛出警告,建议你在配置中添加该包名。

config/index.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
---
2+
title: 配置 Vite
3+
---
4+
15
# 配置 Vite {#configuring-vite}
26

3-
当以命令行方式运行 `vite` 时,Vite 会自动解析 [项目根目录](/guide/#index-html-and-project-root) 下名为 `vite.config.js` 的文件
7+
当以命令行方式运行 `vite` 时,Vite 会自动解析 [项目根目录](/guide/#index-html-and-project-root) 下名为 `vite.config.js` 的配置文件(也支持其他 JS 和 TS 扩展名)
48

59
最基础的配置文件是这样的:
610

@@ -67,7 +71,7 @@ export default defineConfig(({ command, mode, ssrBuild }) => {
6771

6872
## 异步配置 {#async-config}
6973

70-
如果配置需要调用一个异步函数,也可以转而导出一个异步函数:
74+
如果配置需要调用一个异步函数,也可以转而导出一个异步函数。这个异步函数也可以通过 `defineConfig` 传递,以便获得更好的智能提示
7175

7276
```js
7377
export default defineConfig(async ({ command, mode }) => {
@@ -94,7 +98,7 @@ export default defineConfig(({ command, mode }) => {
9498
return {
9599
// vite 配置
96100
define: {
97-
__APP_ENV__: env.APP_ENV,
101+
__APP_ENV__: JSON.stringify(env.APP_ENV),
98102
},
99103
}
100104
})

config/server-options.md

+15-21
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,11 @@ export default defineConfig({
213213
## server.middlewareMode {#server-middlewaremode}
214214

215215
- **类型:** `'ssr' | 'html'`
216+
- **默认值:** `false`
216217

217-
以中间件模式创建 Vite 服务器。(不含 HTTP 服务器)
218+
以中间件模式创建 Vite 服务器。
218219

219-
- `'ssr'` 将禁用 Vite 自身的 HTML 服务逻辑,因此你应该手动为 `index.html` 提供服务。
220-
- `'html'` 将启用 Vite 自身的 HTML 服务逻辑。
221-
222-
- **相关:** [SSR - 设置开发服务器](/guide/ssr#setting-up-the-dev-server)
220+
- **相关:** [appType](./shared-options#apptype)[SSR - 设置开发服务器](/guide/ssr#setting-up-the-dev-server)
223221

224222
- **示例:**
225223

@@ -239,21 +237,16 @@ async function createServer() {
239237
app.use(vite.middlewares)
240238

241239
app.use('*', async (req, res) => {
242-
// 如果 `middlewareMode` 是 `'ssr'`,应在此为 `index.html` 提供服务.
243-
// 如果 `middlewareMode` 是 `'html'`,则此处无需手动服务 `index.html`
244-
// 因为 Vite 自会接管
240+
// 由于 `appType` 的值是 `'custom'`,因此应在此处提供响应。
241+
// 请注意:如果 `appType` 值为 `'spa'` 或 `'mpa'`,Vite 会包含
242+
// 处理 HTML 请求和 404 的中间件,因此用户中间件应该在
243+
// Vite 的中间件之前添加,以确保其生效。
245244
})
246245
}
247246

248247
createServer()
249248
```
250249

251-
## server.base {#server-base}
252-
253-
- **类型:** `string | undefined`
254-
255-
在 HTTP 请求中预留此文件夹,用于代理 Vite 作为子文件夹时使用。应该以 `/` 字符开始。
256-
257250
## server.fs.strict {#server-fs-strict}
258251

259252
- **类型:** `boolean`
@@ -267,6 +260,8 @@ createServer()
267260

268261
限制哪些文件可以通过 `/@fs/` 路径提供服务。当 `server.fs.strict` 设置为 true 时,访问这个目录列表外的文件将会返回 403 结果。
269262

263+
可以提供目录和文件。
264+
270265
Vite 将会搜索此根目录下潜在工作空间并作默认使用。一个有效的工作空间应符合以下几个条件,否则会默认以 [项目 root 目录](/guide/#index-html-and-project-root) 作备选方案。
271266

272267
-`package.json` 中包含 `workspaces` 字段
@@ -299,10 +294,11 @@ export default defineConfig({
299294
// 搜索工作区的根目录
300295
searchForWorkspaceRoot(process.cwd()),
301296
// 自定义规则
302-
'/path/to/custom/allow'
303-
]
304-
}
305-
}
297+
'/path/to/custom/allow_directory',
298+
'/path/to/custom/allow_file.demo',
299+
],
300+
},
301+
},
306302
})
307303
```
308304

@@ -311,9 +307,7 @@ export default defineConfig({
311307
- **类型:** `string[]`
312308
- **默认:** `['.env', '.env.*', '*.{crt,pem}']`
313309

314-
用于限制 Vite 开发服务器提供敏感文件的黑名单。
315-
316-
默认为 `['.env', '.env.*', '*.{pem,crt}']`。这会比 [`server.fs.allow`](#server-fs-allow) 选项的优先级更高。同时还支持 [picomatch patterns](https://github.com/micromatch/picomatch#globbing-features)
310+
用于限制 Vite 开发服务器提供敏感文件的黑名单。这会比 [`server.fs.allow`](#server-fs-allow) 选项的优先级更高。同时还支持 [picomatch 模式](https://github.com/micromatch/picomatch#globbing-features)
317311

318312
## server.origin {#server-origin}
319313

config/shared-options.md

+43-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ interface CSSModulesOptions {
210210

211211
配置 CSS modules 的行为。选项将被传递给 [postcss-modules](https://github.com/css-modules/postcss-modules)
212212

213+
当使用 [Lightning CSS](../guide/features.md#lightning-css) 时,该选项不会产生任何效果。如果要启用该选项,则应该使用 [`css.lightningcss.cssModules`](https://lightningcss.dev/css-modules.html) 来替代。
214+
213215
## css.postcss {#css-postcss}
214216

215217
- **类型:** `string | (postcss.ProcessOptions & { plugins?: postcss.AcceptedPlugin[] })`
@@ -258,12 +260,52 @@ export default defineConfig({
258260

259261
## css.devSourcemap {#css-devsourcemap}
260262

261-
- **实验性**
263+
- **实验性** [提供反馈](https://github.com/vitejs/vite/discussions/13845)
262264
- **类型:** `boolean`
263265
- **默认:** `false`
264266

265267
在开发过程中是否启用 sourcemap。
266268

269+
## css.transformer
270+
271+
- **实验性:** [提供反馈](https://github.com/vitejs/vite/discussions/13835)
272+
- **类型:** `'postcss' | 'lightningcss'`
273+
- **默认:** `'postcss'`
274+
275+
该选项用于选择用于 CSS 处理的引擎。详细信息请查看 [Lightning CSS](../guide/features.md#lightning-css)
276+
277+
## css.lightningcss
278+
279+
- **实验性:** [提供反馈](https://github.com/vitejs/vite/discussions/13835)
280+
- **类型:**
281+
282+
```js
283+
import type {
284+
CSSModulesConfig,
285+
Drafts,
286+
Features,
287+
NonStandard,
288+
PseudoClasses,
289+
Targets,
290+
} from 'lightningcss'
291+
```
292+
293+
```js
294+
{
295+
targets?: Targets
296+
include?: Features
297+
exclude?: Features
298+
drafts?: Drafts
299+
nonStandard?: NonStandard
300+
pseudoClasses?: PseudoClasses
301+
unusedSymbols?: string[]
302+
cssModules?: CSSModulesConfig,
303+
// ...
304+
}
305+
```
306+
307+
该选项用于配置 Lightning CSS。有关完整的转换选项,请参阅 [Lightning CSS 仓库](https://github.com/parcel-bundler/lightningcss/blob/master/node/index.d.ts)
308+
267309
## json.namedExports {#json-namedexports}
268310

269311
- **类型:** `boolean`

config/ssr-options.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ SSR 服务器的构建目标。
2323

2424
## ssr.format
2525

26-
- **实验性**
26+
- **实验性:** [CJS 的支持将在 Vite 5 中移除](https://github.com/vitejs/vite/discussions/13816)
27+
- **弃用** 在 Vite 5 将只支持 ESM 输出
2728
- **类型:** `'esm' | 'cjs'`
2829
- **默认:** `esm`
2930

guide/api-hmr.md

+2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ import.meta.hot.accept((module) => {
174174
- `'vite:beforePrune'` 当不再需要的模块即将被剔除时
175175
- `'vite:invalidate'` 当使用 `import.meta.hot.invalidate()` 使一个模块失效时
176176
- `'vite:error'` 当发生错误时(例如,语法错误)
177+
- `'vite:ws:disconnect'` 当 WebSocket 链接丢失时
178+
- `'vite:ws:connect'` 当 WebSocket 链接重修建立时
177179
178180
自定义 HMR 事件可以由插件发送。更多细节详见 [handleHotUpdate](./api-plugin#handleHotUpdate)。
179181

guide/api-javascript.md

+4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ function mergeConfig(
264264

265265
深度合并两份配置。`isRoot` 代表着 Vite 配置被合并的层级。举个例子,如果你是要合并两个 `build` 选项请设为 `false`
266266

267+
::: tip NOTE
268+
`mergeConfig` 只接受对象形式的配置。如果有一个回调形式的配置,应该在将其传递给 `mergeConfig` 之前先调用该回调函数,将其转换成对象形式。
269+
:::
270+
267271
## `searchForWorkspaceRoot`
268272

269273
**类型签名:**

0 commit comments

Comments
 (0)