Skip to content

Commit 9f83a65

Browse files
authored
Merge pull request #798 from vitejs/develop/sync
2 parents 5e12338 + 55c6c7a commit 9f83a65

17 files changed

+549
-81
lines changed

.vitepress/config.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ export default defineConfig({
4949
pattern: 'https://github.com/vitejs/docs-cn/edit/main/:path',
5050
text: '为此页提供修改建议',
5151
},
52-
53-
outlineTitle: '本页目录',
52+
53+
outline: {
54+
label: '本页目录'
55+
},
5456

5557
socialLinks: [
5658
{ icon: 'mastodon', link: 'https://elk.zone/m.webtoo.ls/@vite' },
@@ -65,7 +67,45 @@ export default defineConfig({
6567
indexName: 'vitejs',
6668
searchParameters: {
6769
facetFilters: ['tags:cn']
68-
}
70+
},
71+
placeholder: '搜索文档',
72+
translations: {
73+
button: {
74+
buttonText: '搜索'
75+
},
76+
modal: {
77+
searchBox: {
78+
resetButtonTitle: '清除查询条件',
79+
resetButtonAriaLabel: '清除查询条件',
80+
cancelButtonText: '取消',
81+
cancelButtonAriaLabel: '取消'
82+
},
83+
startScreen: {
84+
recentSearchesTitle: '搜索历史',
85+
noRecentSearchesText: '没有搜索历史',
86+
saveRecentSearchButtonTitle: '保存到搜索历史',
87+
removeRecentSearchButtonTitle: '从搜索历史中移除',
88+
favoriteSearchesTitle: '收藏',
89+
removeFavoriteSearchButtonTitle: '从收藏中移除'
90+
},
91+
errorScreen: {
92+
titleText: '无法获取结果',
93+
helpText: '你可能需要检查你的网络连接'
94+
},
95+
footer: {
96+
selectText: '选择',
97+
navigateText: '切换',
98+
closeText: '关闭',
99+
searchByText: '搜索供应商'
100+
},
101+
noResultsScreen: {
102+
noResultsText: '无法找到相关结果',
103+
suggestedQueryText: '你可以尝试查询',
104+
reportMissingResultsText: '你认为这个查询应该有结果?',
105+
reportMissingResultsLinkText: '向我们反馈'
106+
}
107+
}
108+
},
69109
},
70110

71111
carbonAds: {

LICENSE

Lines changed: 437 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $ pnpm dev
5656

5757
## 版权声明
5858

59-
本仓库所包含的中文翻译内容(即所有 `.md` 文件),其版权为 Vite 官方中文翻译团队所有。除官方中文文档 [cn.vitejs.dev](https://cn.vitejs.dev) 之外,不得在其它域名下进行未经授权的转载或部署
59+
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 (CC BY-NC-SA 4.0) </a>进行许可
6060

6161
## 贡献者统计
6262

@@ -65,5 +65,7 @@ $ pnpm dev
6565
> 头像图生成逻辑参见:[github-contributor-svg-generator](https://github.com/ShenQingchuan/github-contributor-svg-generator)
6666
6767
<p align="center">
68-
<img src="https://cdn.jsdelivr.net/gh/ShenQingchuan/github-contributor-svg-generator@main/dist/vitejs/docs-cn.png" />
68+
<a href="https://cdn.jsdelivr.net/gh/ShenQingchuan/github-contributor-svg-generator@main/.github-contributors/vitejs_docs-cn.svg">
69+
<img src="https://cdn.jsdelivr.net/gh/ShenQingchuan/github-contributor-svg-generator@main/.github-contributors/vitejs_docs-cn.svg" />
70+
</a>
6971
</p>

config/build-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含它们所
129129
- **类型:** `boolean | 'inline' | 'hidden'`
130130
- **默认:** `false`
131131
132-
构建后是否生成 source map 文件。如果为 `true`,将会创建一个独立的 source map 文件。如果为 `'inline'`,source map 将作为一个 data URI 附加在输出文件中。`'hidden'` 的工作原理与 `'true'` 相似,只是 bundle 文件中相应的注释将不被保留。
132+
构建后是否生成 source map 文件。如果为 `true`,将会创建一个独立的 source map 文件。如果为 `'inline'`,source map 将作为一个 data URI 附加在输出文件中。`'hidden'` 的工作原理与 `true` 相似,只是 bundle 文件中相应的注释将不被保留。
133133
134134
## build.rollupOptions {#build-rollupoptions}
135135

config/dep-optimization-options.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default defineConfig({
4949

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

52-
在部署扫描和优化过程中传递给 esbuild 的选项。
52+
在依赖扫描和优化过程中传递给 esbuild 的选项。
5353

5454
某些选项进行了省略,因为修改它们与 Vite 的优化方案并不兼容。
5555

@@ -78,7 +78,7 @@ export default defineConfig({
7878

7979
## optimizeDeps.needsInterop
8080

81-
- **Experimental**
82-
- **Type:** `string[]`
81+
- **实验性**
82+
- **类型:** `string[]`
8383

84-
Forces ESM interop when importing these dependencies. Vite is able to properly detect when a dependency needs interop, so this option isn't generally needed. However, different combinations of dependencies could cause some of them to be prebundled differently. Adding these packages to `needsInterop` can speed up cold start by avoiding full-page reloads. You'll receive a warning if this is the case for one of your dependencies, suggesting to add the package name to this array in your config.
84+
当导入这些依赖项时,会强制 ESM 转换。Vite 能够正确检测到依赖项是否需要转换处理(interop),因此通常不需要使用此选项。然而,不同的依赖项组合可能导致其中一些包以不同方式预构建。将这些包添加到 `needsInterop` 中可以通过避免重新加载整个页面、加快冷启动速度。如果某个依赖项符合此情况,Vite 将抛出警告,建议你在配置中添加该包名。

config/preview-options.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## preview.host {#preview-host}
44

55
- **类型:** `string | boolean`
6-
- **默认:** [`server.host`](#server_host)
6+
- **默认:** [`server.host`](./server-options#server-host)
77

88
为开发服务器指定 ip 地址。
99
设置为 `0.0.0.0``true` 会监听所有地址,包括局域网和公共地址。
@@ -40,23 +40,23 @@ export default defineConfig({
4040
## preview.strictPort {#preview-strictport}
4141

4242
- **类型:** `boolean`
43-
- **默认:** [`server.strictPort`](#server_strictport)
43+
- **默认:** [`server.strictPort`](./server-options#server-strictport)
4444

4545
设置为 `true` 时,如果端口已被使用,则直接退出,而不会再进行后续端口的尝试。
4646

4747
## preview.https {#preview-https}
4848

4949
- **类型:** `boolean | https.ServerOptions`
50-
- **默认:** [`server.https`](#server_https)
50+
- **默认:** [`server.https`](./server-options#server-https)
5151

52-
启用 TLS + HTTP/2。注意,只有在与 [`server.proxy` 选项](#server-proxy) 同时使用时,才会降级为 TLS。
52+
启用 TLS + HTTP/2。注意,只有在与 [`server.proxy` 选项](./server-options#server-proxy) 同时使用时,才会降级为 TLS。
5353

5454
该值也可以传递给 `https.createServer()`[options 对象](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener)
5555

5656
## preview.open {#preview-open}
5757

5858
- **类型:** `boolean | string`
59-
- **默认:** [`server.open`](#server_open)
59+
- **默认:** [`server.open`](./server-options#server-open)
6060

6161
开发服务器启动时,自动在浏览器中打开应用程序。当该值为字符串时,它将被用作 URL 的路径名。如果你想在你喜欢的某个浏览器打开该开发服务器,你可以设置环境变量 `process.env.BROWSER` (例如 `firefox`)。欲了解更多细节,请参阅 [`open` 包的源码](https://github.com/sindresorhus/open#app)
6262

@@ -74,12 +74,12 @@ export default defineConfig({
7474
## preview.cors {#preview-cors}
7575

7676
- **类型:** `boolean | CorsOptions`
77-
- **默认:** [`server.cors`](#server_proxy)
77+
- **默认:** [`server.cors`](./server-options#server-cors)
7878

7979
为开发服务器配置 CORS。此功能默认启用并支持任何来源。可传递一个 [options 对象](https://github.com/expressjs/cors#configuration-options) 来进行配置,或者传递 `false` 来禁用此行为。
8080

8181
## preview.headers {#preview-headers}
8282

8383
- **类型:** `OutgoingHttpHeaders`
8484

85-
指明服务器返回的响应头。
85+
指明服务器返回的响应头。

config/server-options.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
第一种情况是 `localhost` 被使用了。Node.js 在 v17 以下版本中默认会对 DNS 解析地址的结果进行重新排序。当访问 `localhost` 时,浏览器使用 DNS 来解析地址,这个地址可能与 Vite 正在监听的地址不同。当地址不一致时,Vite 会打印出来。
1818

19-
你可以设置 [`dns.setDefaultResultOrder('verbatim')`](https://nodejs.org/api/dns.html#dns_dns_setdefaultresultorder_order) 来禁用这个重新排序的行为。Vite 将会将改地址打印为 `localhost`
19+
你可以设置 [`dns.setDefaultResultOrder('verbatim')`](https://nodejs.org/api/dns.html#dns_dns_setdefaultresultorder_order) 来禁用这个重新排序的行为。Vite 会将地址打印为 `localhost`
2020

2121
```js
2222
// vite.config.js
@@ -34,7 +34,6 @@ export default defineConfig({
3434

3535
:::
3636

37-
3837
::: tip 在 WSL2 中通过 LAN 访问开发服务器
3938

4039
当你在 WSL2 运行 Vite 时,仅设置 `host: true` 来从局域网访问服务器是不够的。
@@ -214,13 +213,11 @@ export default defineConfig({
214213
## server.middlewareMode {#server-middlewaremode}
215214

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

218-
以中间件模式创建 Vite 服务器。(不含 HTTP 服务器)
219-
220-
- `'ssr'` 将禁用 Vite 自身的 HTML 服务逻辑,因此你应该手动为 `index.html` 提供服务。
221-
- `'html'` 将启用 Vite 自身的 HTML 服务逻辑。
218+
以中间件模式创建 Vite 服务器。
222219

223-
- **相关:** [SSR - 设置开发服务器](/guide/ssr#setting-up-the-dev-server)
220+
- **相关:** [appType](./shared-options#apptype)[SSR - 设置开发服务器](/guide/ssr#setting-up-the-dev-server)
224221

225222
- **示例:**
226223

@@ -240,9 +237,10 @@ async function createServer() {
240237
app.use(vite.middlewares)
241238

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

@@ -309,9 +307,7 @@ export default defineConfig({
309307
- **类型:** `string[]`
310308
- **默认:** `['.env', '.env.*', '*.{crt,pem}']`
311309

312-
用于限制 Vite 开发服务器提供敏感文件的黑名单。
313-
314-
默认为 `['.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)
315311

316312
## server.origin {#server-origin}
317313

guide/api-javascript.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))
3434
```
3535

3636
::: tip 注意
37-
当在同一个 Node.js 进程中使用 `createServer``build` 时,两个函数都依赖于 `process.env.NODE_ENV` 才可正常工作,而这个环境变量又依赖于 `mode` 配置项。为了避免行为冲突,请在这两个 API 传入参数 `development` 字段中设置 `process.env.NODE_ENV` 或者 `mode` 配置项,或者你也可以生成另一个子进程,分别运行这两个 API
37+
当在同一个 Node.js 进程中使用 `createServer``build` 时,两个函数都依赖于 `process.env.NODE_ENV` 才可正常工作,而这个环境变量又依赖于 `mode` 配置项。为了避免行为冲突,请在使用这两个 API 时为 `process.env.NODE_ENV` 或者 `mode` 配置项、字段设置参数值 `development`,或者你也可以生成另一个子进程,分别运行这两个 API
3838
:::
3939

4040
## `InlineConfig` {#inlineconfig}
@@ -265,11 +265,7 @@ function mergeConfig(
265265
深度合并两份配置。`isRoot` 代表着 Vite 配置被合并的层级。举个例子,如果你是要合并两个 `build` 选项请设为 `false`
266266

267267
::: tip NOTE
268-
`mergeConfig` accepts only config in object form. If you have a config in callback form, you should call it before passing into `mergeConfig`.
269-
:::
270-
271-
::: tip NOTE
272-
`mergeConfig` accepts only config in object form. If you have a config in callback form, you should call it before passing into `mergeConfig`.
268+
`mergeConfig` 只接受对象形式的配置。如果有一个回调形式的配置,应该在将其传递给 `mergeConfig` 之前先调用该回调函数,将其转换成对象形式。
273269
:::
274270

275271
## `searchForWorkspaceRoot`

guide/api-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ console.log(msg)
161161

162162
它们还有一个扩展的 `options` 参数,包含其他特定于 Vite 的属性。你可以在 [SSR 文档](/guide/ssr#ssr-specific-plugin-logic) 中查阅更多内容。
163163

164-
一些 `resolveId` 调用的 `importer` 值可能是根目录下的通用 `index.html` 的绝对路径,因为由于 Vite 非打包的开发服务器模式无法始终推导出实际的导入者。对于在 Vite 的解析管道中处理的导入,导入者可以在导入分析阶段进行跟踪,那时所提供的 `importer` 值是正确的
164+
一些 `resolveId` 调用的 `importer` 值可能是根目录下的通用 `index.html` 的绝对路径,这是由于 Vite 非打包的开发服务器模式无法始终推断出实际的导入者。对于在 Vite 的解析管道中处理的导入,可以在导入分析阶段跟踪导入者,提供正确的 `importer`
165165

166166
以下钩子在服务器关闭时被调用:
167167

guide/comparisons.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Preact 团队的 [WMR](https://github.com/preactjs/wmr) 提供了类似的特性
66

77
WMR 主要是为了 [Preact](https://preactjs.com/) 项目而设计,并为其提供了集成度更高的功能,比如预渲染。就使用范围而言,它更加贴合于 Preact 框架,与 Preact 本身一样强调紧凑的大小。如果你正在使用 Preact,那么 WMR 可能会提供更好的体验。
88

9-
## @web/dev-server {#webdev-server}
9+
## @web/dev-server {#web-dev-server}
1010

1111
[@web/dev-server](https://modern-web.dev/docs/dev-server/overview/)(曾经是 `es-dev-server`)是一个伟大的项目,基于 koa 的 Vite 1.0 开发服务器就是受到了它的启发。
1212

@@ -16,6 +16,6 @@ WMR 主要是为了 [Preact](https://preactjs.com/) 项目而设计,并为其
1616

1717
## Snowpack {#snowpack}
1818

19-
[Snowpack](https://www.snowpack.dev/) 也是一个与 Vite 十分类似的非构建式原生 ESM 开发服务器。该项目已经不维护了。团队目前正在开发 [Astro](https://astro.build/),一个由 Vite 驱动的静态站点构建工具。Astro 团队目前是我们生态中非常活跃的成员,它们帮助 Vite 进益良多。
19+
[Snowpack](https://www.snowpack.dev/) 也是一个与 Vite 十分类似的非构建式原生 ESM 开发服务器。该项目已经不维护了。团队目前正在开发 [Astro](https://astro.build/),一个由 Vite 驱动的静态站点构建工具。Astro 团队目前是我们生态中非常活跃的成员,他们帮助 Vite 进益良多。
2020

21-
除了不同的实现细节外,这两个项目在技术上比传统工具有很多共同优势。Vite 的依赖预构建也受到了 Snowpack v1(现在是 [`esinstall`](https://github.com/snowpackjs/snowpack/tree/main/esinstall))的启发。若想了解 Vite 同这两个项目之间的一些主要区别,可以查看 [the v2 Comparisons Guide](https://v2.vitejs.dev/guide/comparisons)
21+
除了不同的实现细节外,这两个项目在技术上比传统工具有很多共同优势。Vite 的依赖预构建也受到了 Snowpack v1(现在是 [`esinstall`](https://github.com/snowpackjs/snowpack/tree/main/esinstall))的启发。若想了解 Vite 同这两个项目之间的一些主要区别,可以查看 [Vite v2 比较指南](https://v2.vitejs.dev/guide/comparisons)

0 commit comments

Comments
 (0)