Skip to content

Commit 5e47c03

Browse files
authored
docs(cn): update with main stream
release v4.3.0
2 parents 291a25b + b3e88da commit 5e47c03

15 files changed

+229
-20
lines changed

.vitepress/config.ts

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ export default defineConfig({
4141
pt: { label: 'Português', link: 'https://pt.vitejs.dev' },
4242
},
4343

44-
vue: {
45-
reactivityTransform: true,
46-
},
47-
4844
themeConfig: {
4945
logo: '/logo.svg',
5046

.vitepress/theme/components/HomeSponsors.vue

+53-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,59 @@ const { data } = useSponsor()
99
<VPHomeSponsors
1010
v-if="data"
1111
message="Vite is free and open source, made possible by wonderful sponsors."
12-
action-text="Become a sponsor"
13-
action-link="https://github.com/sponsors/yyx990803"
1412
:data="data"
1513
/>
14+
<div class="action">
15+
<a
16+
class="sponsor"
17+
href="https://github.com/sponsors/vitejs"
18+
target="_blank"
19+
rel="noreferrer"
20+
>
21+
Sponsor Vite
22+
</a>
23+
<a
24+
class="sponsor"
25+
href="https://github.com/sponsors/yyx990803"
26+
target="_blank"
27+
rel="noreferrer"
28+
>
29+
Sponsor Evan You
30+
</a>
31+
</div>
1632
</template>
33+
34+
<style scoped>
35+
.action {
36+
display: flex;
37+
justify-content: center;
38+
gap: 1rem;
39+
padding-top: 4rem;
40+
}
41+
42+
.sponsor {
43+
/* .VPButton */
44+
display: inline-block;
45+
border: 1px solid transparent;
46+
text-align: center;
47+
font-weight: 600;
48+
white-space: nowrap;
49+
transition: color 0.25s, border-color 0.25s, background-color 0.25s;
50+
/* .VPButton.medium */
51+
border-radius: 20px;
52+
padding: 0 20px;
53+
line-height: 38px;
54+
font-size: 14px;
55+
/* .VPButton.sponsor */
56+
border-color: var(--vp-button-sponsor-border);
57+
color: var(--vp-button-sponsor-text);
58+
background-color: var(--vp-button-sponsor-bg);
59+
}
60+
61+
.sponsor:hover {
62+
/* .VPButton.sponsor:hover */
63+
border-color: var(--vp-button-sponsor-hover-border);
64+
color: var(--vp-button-sponsor-hover-text);
65+
background-color: var(--vp-button-sponsor-hover-bg);
66+
}
67+
</style>

.vitepress/theme/composables/sponsor.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ 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'> = {
26+
gold: [],
27+
}
28+
2429
export function useSponsor() {
2530
onMounted(async () => {
2631
if (data.value) {
@@ -48,7 +53,7 @@ function mapSponsors(sponsors: Sponsors) {
4853
{
4954
tier: 'Gold Sponsors',
5055
size: 'medium',
51-
items: mapImgPath(sponsors['gold']),
56+
items: viteSponsors['gold'].concat(mapImgPath(sponsors['gold'])),
5257
},
5358
]
5459
}

_data/team.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,23 @@ export const core = [
120120
name: 'Dominik G.',
121121
title: 'Resident CI Expert',
122122
desc: 'Team Member of Vite and Svelte',
123-
links: [{ icon: 'github', link: 'https://github.com/dominikg' }],
123+
links: [
124+
{ icon: 'github', link: 'https://github.com/dominikg' },
125+
{ icon: 'mastodon', link: 'https://elk.zone/m.webtoo.ls/@dominikg' },
126+
],
127+
sponsor: 'https://github.com/sponsors/dominikg',
128+
},
129+
{
130+
avatar: 'https://github.com/sheremet-va.png',
131+
name: 'Vladimir',
132+
title: 'Core team member of Vitest & Vite',
133+
desc: 'An open source fullstack developer',
134+
links: [
135+
{ icon: 'github', link: 'https://github.com/sheremet-va' },
136+
{ icon: 'mastodon', link: 'https://elk.zone/m.webtoo.ls/@sheremet_va' },
137+
{ icon: 'twitter', link: 'https://twitter.com/sheremet_va' },
138+
],
139+
sponsor: 'https://github.com/sponsors/sheremet-va',
124140
},
125141
]
126142

blog/announcing-vite4-3.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
sidebar: false
3+
head:
4+
- - meta
5+
- property: og:type
6+
content: website
7+
- - meta
8+
- property: og:title
9+
content: Announcing Vite 4.3
10+
- - meta
11+
- property: og:image
12+
content: https://vitejs.dev/og-image-announcing-vite4-3.png
13+
- - meta
14+
- property: og:url
15+
content: https://vitejs.dev/blog/announcing-vite4-3
16+
- - meta
17+
- property: og:description
18+
content: Vite 4.3 Release Announcement
19+
- - meta
20+
- name: twitter:card
21+
content: summary_large_image
22+
---
23+
24+
# Vite 4.3 is out!
25+
26+
_April 20, 2023_
27+
28+
![Vite 4.3 Announcement Cover Image](/og-image-announcing-vite4-3.png)
29+
30+
Quick links:
31+
32+
- Docs: [English](/), [简体中文](https://cn.vitejs.dev/), [日本語](https://ja.vitejs.dev/), [Español](https://es.vitejs.dev/), [Português](https://pt.vitejs.dev/)
33+
- [Vite 4.3 Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#430-2023-04-20)
34+
35+
## Performance Improvements
36+
37+
In this minor, we focused on improving the dev server performance. The resolve logic got streamlined, improving hot paths and implementing smarter caching for finding `package.json`, TS config files, and resolved URL in general.
38+
39+
You can read a detailed walkthrough of the performance work done in this blog post by one of Vite Contributors: [How we made Vite 4.3 faaaaster 🚀](https://sun0day.github.io/blog/vite/why-vite4_3-is-faster.html).
40+
41+
This sprint resulted in speed improvements across the board compared to Vite 4.2.
42+
43+
These are the performance improvements as measured by [sapphi-red/performance-compare](https://github.com/sapphi-red/performance-compare), which tests an app with 1000 React Components cold and warm dev server startup time as well as HMR times for a root and a leaf component:
44+
45+
| **Vite (babel)** | Vite 4.2 | Vite 4.3 | Improvement |
46+
| :----------------- | --------: | -------: | ----------: |
47+
| **dev cold start** | 17249.0ms | 5132.4ms | -70.2% |
48+
| **dev warm start** | 6027.8ms | 4536.1ms | -24.7% |
49+
| **Root HMR** | 46.8ms | 26.7ms | -42.9% |
50+
| **Leaf HMR** | 27.0ms | 12.9ms | -52.2% |
51+
52+
| **Vite (swc)** | Vite 4.2 | Vite 4.3 | Improvement |
53+
| :----------------- | --------: | -------: | ----------: |
54+
| **dev cold start** | 13552.5ms | 3201.0ms | -76.4% |
55+
| **dev warm start** | 4625.5ms | 2834.4ms | -38.7% |
56+
| **Root HMR** | 30.5ms | 24.0ms | -21.3% |
57+
| **Leaf HMR** | 16.9ms | 10.0ms | -40.8% |
58+
59+
![Vite 4.3 vs 4.2 startup time comparison](/vite4-3-startup-time.png)
60+
61+
![Vite 4.3 vs 4.2 HMR time comparison](/vite4-3-hmr-time.png)
62+
63+
You can read more information about the benchmark [here](https://gist.github.com/sapphi-red/25be97327ee64a3c1dce793444afdf6e). Specs and Versions for this performance run:
64+
65+
- CPU: Ryzen 9 5900X, Memory: DDR4-3600 32GB, SSD: WD Blue SN550 NVME SSD
66+
- Windows 10 Pro 21H2 19044.2846
67+
- Node.js 18.16.0
68+
- Vite and React Plugin versions
69+
- Vite 4.2 (babel): Vite 4.2.1 + plugin-react 3.1.0
70+
- Vite 4.3 (babel): Vite 4.3.0 + plugin-react 4.0.0-beta.1
71+
- Vite 4.2 (swc): Vite 4.2.1 + plugin-react-swc 3.2.0
72+
- Vite 4.3 (swc): Vite 4.3.0 + plugin-react-swc 3.3.0
73+
74+
Early adopters have also reported seeing 1.5x-2x dev startup time improvement on real apps while testing the Vite 4.3 beta. We'd love to know the results for your apps.
75+
76+
## Profiling
77+
78+
We'll continue to work on Vite's performance. We're working on an official [Benchmark tool](https://github.com/vitejs/vite-benchmark) for Vite that let us get performance metrics for each Pull Request.
79+
80+
And [vite-plugin-inspect](https://github.com/antfu/vite-plugin-inspect) now has more performance-related features to help you identify which plugins or middlewares are the bottleneck for your applications.
81+
82+
Using `vite --profile` (and then pressing `p`) once the page loads will save a CPU profile of the dev server startup. You can open them in an app as [speedscope](https://www.speedscope.app/) to identify performance issues. And you can share your findings with the Vite Team in a [Discussion](https://github.com/vitejs/vite/discussions) or in [Vite's Discord](https://chat.vitejs.dev).
83+
84+
## Next Steps
85+
86+
We decided to do a single Vite Major this year aligning with the [EOL of Node.js 16](https://endoflife.date/nodejs) in September, dropping support for both Node.js 14 and 16 in it. If you would like to get involved, we started a [Vite 5 Discussion](https://github.com/vitejs/vite/discussions/12466) to gather early feedback.

config/server-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export default defineConfig({
327327
- **类型:** `false | (sourcePath: string, sourcemapPath: string) => boolean`
328328
- **默认:** `(sourcePath) => sourcePath.includes('node_modules')`
329329

330-
是否忽略服务器 sourcemap 中的源文件,用于填充 [`x_google_ignoreList` source map 扩展](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension)
330+
是否忽略服务器 sourcemap 中的源文件,用于填充 [`x_google_ignoreList` source map 扩展](https://developer.chrome.com/articles/x-google-ignore-list/)
331331

332332
对开发服务器来说 `server.sourcemapIgnoreList` 等价于 [`build.rollupOptions.output.sourcemapIgnoreList`](https://rollupjs.org/configuration-options/#output-sourcemapignorelist)。两个配置选项之间的区别在于,rollup 函数使用相对路径调用 `sourcePath`,而 `server.sourcemapIgnoreList` 使用绝对路径调用。在开发过程中,大多数模块的映射和源文件位于同一个文件夹中,因此 `sourcePath` 的相对路径就是文件名本身。在这些情况下,使用绝对路径更加方便。
333333

config/shared-options.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const obj = {
111111
更高级的自定义解析方法可以通过 [插件](/guide/api-plugin) 实现。
112112

113113
::: warning 在 SSR 中使用
114-
如果你已经为 [SSR 外部化的依赖](/guide/ssr.md#ssr-externals) 配置了别名,你可能想要为真实的 `node_modules` 包配别名. [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias)[pnpm](https://pnpm.js.org/en/aliases) 都支持通过 `npm:` 前缀配置别名。
114+
如果你已经为 [SSR 外部化的依赖](/guide/ssr.md#ssr-externals) 配置了别名,你可能想要为真实的 `node_modules` 包配别名[Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias)[pnpm](https://pnpm.io/aliases/) 都支持通过 `npm:` 前缀配置别名。
115115
:::
116116

117117
## resolve.dedupe {#resolve-dedupe}
@@ -232,7 +232,7 @@ interface CSSModulesOptions {
232232
- `less` - [选项](https://lesscss.org/usage/#less-options)
233233
- `styl`/`stylus` - 仅支持 [`define`](https://stylus-lang.com/docs/js.html#define-name-node),可以作为对象传递。
234234

235-
所有预处理器选项还支持 `additionalData` 选项,可以用于为每个样式内容注入额外代码。
235+
所有预处理器选项还支持 `additionalData` 选项,可以用于为每个样式内容注入额外代码。请注意,如果注入的是实际的样式而不仅仅是变量时,那么这些样式将会在最终的打包产物中重复出现。
236236

237237
示例:
238238

guide/api-javascript.md

+40
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,46 @@ import { preview } from 'vite'
196196
})()
197197
```
198198

199+
## `PreviewServer`
200+
201+
```ts
202+
interface PreviewServer extends PreviewServerForHook {
203+
resolvedUrls: ResolvedServerUrls
204+
}
205+
```
206+
207+
## `PreviewServerForHook`
208+
209+
```ts
210+
interface PreviewServerForHook {
211+
/**
212+
* 解析后的 vite 配置对象
213+
*/
214+
config: ResolvedConfig
215+
/**
216+
* 一个 connect 应用实例。
217+
* - 可用作将自定义中间件附加到预览服务器上。
218+
* - 还可用作自定义 HTTP 服务器的处理函数
219+
* 或作为任何 connect 风格的 Node.js 框架的中间件
220+
*
221+
* https://github.com/senchalabs/connect#use-middleware
222+
*/
223+
middlewares: Connect.Server
224+
/**
225+
* 原生 Node http 服务器实例
226+
*/
227+
httpServer: http.Server
228+
/**
229+
* Vite 在 CLI 中输出的解析后的 URL
230+
*/
231+
resolvedUrls: ResolvedServerUrls | null
232+
/**
233+
* 打印服务器 URL
234+
*/
235+
printUrls(): void
236+
}
237+
```
238+
199239
## `resolveConfig` {#resolveconfig}
200240

201241
**类型校验:**

guide/api-plugin.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,11 @@ Vite 插件也可以提供钩子来服务于特定的 Vite 目标。这些钩子
309309

310310
### `configurePreviewServer` {#configurepreviewserver}
311311

312-
- **类型:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>`
312+
- **类型:** `(server: PreviewServerForHook) => (() => void) | void | Promise<(() => void) | void>`
313313
- **种类:** `async`, `sequential`
314+
- **参见:** [PreviewServerForHook](./api-javascript#previewserverforhook)
314315

315-
[`configureServer`](/guide/api-plugin.html#configureserver) 相同但是作为预览服务器。它提供了一个 [connect](https://github.com/senchalabs/connect) 服务器实例及其底层的 [http server](https://nodejs.org/api/http.html)。与 `configureServer` 类似,`configurePreviewServer` 这个钩子也是在其他中间件安装前被调用的。如果你想要在其他中间件 **之后** 安装一个插件,你可以从 `configurePreviewServer` 返回一个函数,它将会在内部中间件被安装之后再调用:
316+
[`configureServer`](/guide/api-plugin.html#configureserver) 相同,但用于预览服务器。`configurePreviewServer` 这个钩子与 `configureServer` 类似,也是在其他中间件安装前被调用。如果你想要在其他中间件 **之后** 安装一个插件,你可以从 `configurePreviewServer` 返回一个函数,它将会在内部中间件被安装之后再调用:
316317

317318
```js
318319
const myPlugin = () => ({

guide/features.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export type { T }
7474

7575
如果你正在使用一个严重依赖 class fields 的库,请注意该库对此选项的预期设置。
7676

77-
大多数库都希望 `"useDefineForClassFields": true`,如 [MobX](https://mobx.js.org/installation.html#use-spec-compliant-transpilation-for-class-properties)[Vue Class Components 8.x](https://github.com/vuejs/vue-class-component/issues/465)
77+
大多数库都希望 `"useDefineForClassFields": true`,如 [MobX](https://mobx.js.org/installation.html#use-spec-compliant-transpilation-for-class-properties)
7878

7979
但是有几个库还没有兼容这个新的默认值,其中包括 [`lit-element`](https://github.com/lit/lit-element/issues/1030)。如果遇到这种情况,请将 `useDefineForClassFields` 设置为 `false`
8080

@@ -96,7 +96,7 @@ Vite 默认的类型定义是写给它的 Node.js API 的。要将其补充到
9696
/// <reference types="vite/client" />
9797
```
9898

99-
同时,你也可以将 `vite/client` 添加到 `tsconfig` 中的 `compilerOptions.types` 下:
99+
或者,你也可以将 `vite/client` 添加到 `tsconfig.json` 中的 `compilerOptions.types` 下:
100100

101101
```json
102102
{
@@ -255,6 +255,7 @@ import otherStyles from './bar.css?inline' // 样式不会注入页面
255255
::: tip 注意
256256
自 Vite 4 起,CSS 文件的默认导入和按名导入(例如 `import style from './foo.css'`)将弃用。请使用 `?inline` 参数代替。
257257
:::
258+
258259
## 静态资源处理 {#static-assets}
259260

260261
导入一个静态资源会返回解析后的 URL:
@@ -350,7 +351,7 @@ const modules = {
350351
`import.meta.glob` 都支持以字符串形式导入文件,类似于 [以字符串形式导入资源](https://vitejs.dev/guide/assets.html#importing-asset-as-string)。在这里,我们使用了 [Import Reflection](https://github.com/tc39/proposal-import-reflection) 语法对导入进行断言:
351352

352353
```js
353-
const modules = import.meta.glob('./dir/*.js', { as: 'raw' })
354+
const modules = import.meta.glob('./dir/*.js', { as: 'raw', eager: true })
354355
```
355356

356357
上面的代码会被转换为下面这样:
@@ -460,7 +461,7 @@ const modules = {
460461
}
461462
```
462463

463-
### Glob 导入注意事项
464+
### Glob 导入注意事项 {#glob-import-caveats}
464465

465466
请注意:
466467

guide/ssr.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
7373
async function createServer() {
7474
const app = express()
7575

76-
// 以中间件模式创建 Vite 应用,这将禁用 Vite 自身的 HTML 服务逻辑
76+
// 以中间件模式创建 Vite 应用,并将 appType 配置为 'custom'
77+
// 这将禁用 Vite 自身的 HTML 服务逻辑
7778
// 并让上级服务器接管控制
7879
const vite = await createViteServer({
7980
server: { middlewareMode: true },
@@ -210,10 +211,12 @@ const html = await vueServerRenderer.renderToString(app, ctx)
210211
211212
当运行 SSR 时依赖会由 Vite 的 SSR 转换模块系统作外部化。这会同时提速开发与构建。
212213
213-
例如,如果依赖项需要通过 Vite 的管道进行转换,因为在这些依赖在管道中使用 Vite 特性时是不转翻译的,则可以将它们添加到 [`ssr.noExternal`](../config/ssr-options.md#ssrnoexternal) 中。
214+
如果依赖需要被 Vite 的管道转换,例如因为其中使用了未经过转译的 Vite 特性,那么它们可以被添加到 [`ssr.noExternal`](../config/ssr-options.md#ssr-noexternal) 中。
215+
216+
对于采用链接的依赖,它们将默认不会被外部化,这是为了能使其利用 Vite HMR 的优势。如果你不需要这一功效,例如,想要把这些依赖当成非链接情况来测试,你可以将其添加到 [`ssr.external`](../config/ssr-options.md#ssr-external)。
214217
215218
:::warning 使用别名
216-
如果你为某个包配置了一个别名,为了能使 SSR 外部化依赖功能正常工作,你可能想要使用的别名应该指的是实际的 `node_modules` 中的包。[Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) 和 [pnpm](https://pnpm.js.org/en/aliases) 都支持通过 `npm:` 前缀来设置别名。
219+
如果你为某个包配置了一个别名,为了能使 SSR 外部化依赖功能正常工作,你可能想要使用的别名应该指的是实际的 `node_modules` 中的包。[Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) 和 [pnpm](https://pnpm.io/aliases/) 都支持通过 `npm:` 前缀来设置别名。
217220
:::
218221
219222
## SSR 专有插件逻辑 {#ssr-specific-plugin-logic}

guide/troubleshooting.md

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ import './Foo.js' // 应该为 './foo.js'
121121

122122
你需要通过 `http` 协议访问该文件。最简单的办法就是使用 `npx vite preview`
123123

124+
## 优化依赖 {#optimize-dependencies}
125+
126+
### 链接本地包时过期预构建依赖项 {#outdated-pre-bundled-deps-when-linking-to-a-local-package}
127+
128+
在 Vite 中通过一个哈希值来决定优化后的依赖项是否有效,这个值取决于包锁定的内容、应用于依赖项的补丁以及 Vite 配置文件中影响 node_modules 打包的选项。这意味着,当使用像 [npm overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) 这样的功能覆盖依赖项时,Vite 将检测到,并在下一次服务器启动时重新打包您的依赖项。当您使用像 [npm link](https://docs.npmjs.com/cli/v9/commands/npm-link) 这样的功能时,Vite 不会使依赖项无效。如果您链接或取消链接一个依赖项,那么您需要使用 `vite --force` 在下一次服务器启动时强制重新预构建。我们建议使用 overrides,它们现在被每个包管理器所支持(还可以参见 [pnpm overrides](https://pnpm.io/package_json#pnpmoverrides)[yarn resolutions](https://yarnpkg.com/configuration/manifest/#resolutions))。
129+
124130
## 其他 {#others}
125131

126132
### Module externalized for browser compatibility {#module-externalized-for-browser-compatibility}
@@ -144,3 +150,7 @@ Vite 无法处理、也不支持仅可在非严格模式(sloppy mode)下运
144150
> TypeError: Cannot create property 'foo' on boolean 'false'
145151
146152
如果这些代码是在依赖中被使用的,你应该使用 [`patch-package`](https://github.com/ds300/patch-package)(或者 [`yarn patch`](https://yarnpkg.com/cli/patch)[`pnpm patch`](https://pnpm.io/cli/patch) 工具)来做短期补丁处理。
153+
154+
### 浏览器扩展程序 {#browser-extensions}
155+
156+
一些浏览器扩展程序(例如 ad-blockers 广告拦截器),可能会阻止 Vite 客户端向 Vite 开发服务器发送请求。在这种情况下,你可能会看到一个空白屏且没有错误日志。如果遇到这类问题,请尝试禁用扩展程序。
350 KB
Loading

public/vite4-3-hmr-time.png

95.9 KB
Loading

public/vite4-3-startup-time.png

104 KB
Loading

0 commit comments

Comments
 (0)