Skip to content

Commit 17aa196

Browse files
authored
release: v5.3.1
2 parents 7024051 + 7a31518 commit 17aa196

19 files changed

+703
-697
lines changed

.vitepress/buildEnd.config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import path from 'path'
2-
import { writeFileSync } from 'fs'
1+
import path from 'node:path'
2+
import { writeFileSync } from 'node:fs'
33
import { Feed } from 'feed'
4-
import { createContentLoader, type SiteConfig } from 'vitepress'
4+
import type { SiteConfig } from 'vitepress'
5+
import { createContentLoader } from 'vitepress'
56

67
const siteUrl = 'https://vitejs.dev'
78
const blogUrl = `${siteUrl}/blog`
89

9-
export const buildEnd = async (config: SiteConfig) => {
10+
export const buildEnd = async (config: SiteConfig): Promise<void> => {
1011
const feed = new Feed({
1112
title: 'Vite',
1213
description: 'Next Generation Frontend Tooling',

.vitepress/config.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { defineConfig, DefaultTheme } from 'vitepress'
1+
import type { DefaultTheme } from 'vitepress'
2+
import { defineConfig } from 'vitepress'
23
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
34
import { buildEnd } from './buildEnd.config'
45

@@ -79,6 +80,7 @@ export default defineConfig({
7980
['meta', { property: 'og:image', content: ogImage }],
8081
['meta', { property: 'og:url', content: ogUrl }],
8182
['meta', { property: 'og:description', content: ogDescription }],
83+
['meta', { property: 'og:site_name', content: 'vitejs' }],
8284
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
8385
['meta', { name: 'twitter:site', content: '@vite_js' }],
8486
['meta', { name: 'theme-color', content: '#646cff' }],
@@ -396,10 +398,10 @@ export default defineConfig({
396398
.replace(/\/index\.md$/, '/')
397399
.replace(/\.md$/, '/')
398400
pageData.frontmatter.head ??= []
399-
pageData.frontmatter.head.unshift([
400-
'link',
401-
{ rel: 'canonical', href: canonicalUrl },
402-
])
401+
pageData.frontmatter.head.unshift(
402+
['link', { rel: 'canonical', href: canonicalUrl }],
403+
['meta', { property: 'og:title', content: pageData.title }],
404+
)
403405
return pageData
404406
},
405407
markdown: {

.vitepress/theme/composables/sponsor.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, onMounted, onUnmounted } from 'vue'
1+
import { onMounted, onUnmounted, ref } from 'vue'
22

33
interface Sponsors {
44
special: Sponsor[]
@@ -64,6 +64,16 @@ const viteSponsors: Pick<Sponsors, 'special' | 'gold'> = {
6464
img: '/transloadit.svg',
6565
hasDark: true,
6666
},
67+
{
68+
name: 'Huly',
69+
url: 'https://huly.io/',
70+
img: '/huly.svg',
71+
},
72+
{
73+
name: 'Handsontable',
74+
url: 'https://handsontable.com/docs/react-data-grid/?utm_source=vite_docs&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024',
75+
img: '/handsontable.svg',
76+
},
6777
],
6878
}
6979

blog/announcing-vite3.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ head:
2929

3030
_July 23, 2022_ - Check out the [Vite 4.0 announcement](./announcing-vite4.md)
3131

32-
In February last year, [Evan You](https://twitter.com/youyuxi) released Vite 2. Since then, its adoption has grown non-stop, reaching more than 1 million npm downloads per week. A sprawling ecosystem rapidly formed after the release. Vite is powering a renewed innovation race in Web frameworks. [Nuxt 3](https://v3.nuxtjs.org/) uses Vite by default. [SvelteKit](https://kit.svelte.dev/), [Astro](https://astro.build/), [Hydrogen](https://hydrogen.shopify.dev/), and [SolidStart](https://docs.solidjs.com/start) are all built with Vite. [Laravel has now decided to use Vite by default](https://laravel.com/docs/9.x/vite). [Vite Ruby](https://vite-ruby.netlify.app/) shows how Vite can improve Rails DX. [Vitest](https://vitest.dev) is making strides as a Vite-native alternative to Jest. Vite is behind [Cypress](https://docs.cypress.io/guides/component-testing/writing-your-first-component-test) and [Playwright](https://playwright.dev/docs/test-components)'s new Component Testing features, Storybook has [Vite as an official builder](https://github.com/storybookjs/builder-vite). And [the list goes on](https://patak.dev/vite/ecosystem.html). Maintainers from most of these projects got involved in improving the Vite core itself, working closely with the Vite [team](https://vitejs.dev/team) and other contributors.
32+
In February last year, [Evan You](https://twitter.com/youyuxi) released Vite 2. Since then, its adoption has grown non-stop, reaching more than 1 million npm downloads per week. A sprawling ecosystem rapidly formed after the release. Vite is powering a renewed innovation race in Web frameworks. [Nuxt 3](https://v3.nuxtjs.org/) uses Vite by default. [SvelteKit](https://kit.svelte.dev/), [Astro](https://astro.build/), [Hydrogen](https://hydrogen.shopify.dev/), and [SolidStart](https://docs.solidjs.com/quick-start) are all built with Vite. [Laravel has now decided to use Vite by default](https://laravel.com/docs/9.x/vite). [Vite Ruby](https://vite-ruby.netlify.app/) shows how Vite can improve Rails DX. [Vitest](https://vitest.dev) is making strides as a Vite-native alternative to Jest. Vite is behind [Cypress](https://docs.cypress.io/guides/component-testing/writing-your-first-component-test) and [Playwright](https://playwright.dev/docs/test-components)'s new Component Testing features, Storybook has [Vite as an official builder](https://github.com/storybookjs/builder-vite). And [the list goes on](https://patak.dev/vite/ecosystem.html). Maintainers from most of these projects got involved in improving the Vite core itself, working closely with the Vite [team](https://vitejs.dev/team) and other contributors.
3333

3434
![Vite 3 Announcement Cover Image](/og-image-announcing-vite3.png)
3535

blog/announcing-vite5-1.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Import CSS files as URLs now works reliably and correctly. This was the last rem
6666

6767
### `build.assetsInlineLimit` now supports a callback
6868

69-
Users can now [provide a callback](/config/build-options.html#build-assetsinlinelimit) that returns a boolean to opt-in or opt-out of inlining for specific assets. If `undefined` is returned, the defalt logic applies. See ([#15366](https://github.com/vitejs/vite/issues/15366)).
69+
Users can now [provide a callback](/config/build-options.html#build-assetsinlinelimit) that returns a boolean to opt-in or opt-out of inlining for specific assets. If `undefined` is returned, the default logic applies. See ([#15366](https://github.com/vitejs/vite/issues/15366)).
7070

7171
### Improved HMR for circular import
7272

@@ -82,7 +82,7 @@ The preview server now exposes a `close` method, which will properly teardown th
8282

8383
## Performance improvements
8484

85-
Vite keeps getting faster with each release, and Vite 5.1 is packed with performance improvements. We measured the loading time for 10K modules (25 level deep tree) using [vite-dev-server-perf](https://github.com/yyx990803/vite-dev-server-perf) for all minor versions from Vite 4.0. This is a good benchmark to meassure the effect of Vite's bundle-less approach. Each module is a small TypeScript file with a counter and imports to other files in the tree, so this mostly meassuring the time it takes to do the requests a separate modules. In Vite 4.0, loading 10K modules took 8 seconds on a M1 MAX. We had a breakthrough in [Vite 4.3 were we focused on performance](./announcing-vite4-3.md), and we were able to load them in 6.35 seconds. In Vite 5.1, we managed to do another performance leap. Vite is now serving the 10K modules in 5.35 seconds.
85+
Vite keeps getting faster with each release, and Vite 5.1 is packed with performance improvements. We measured the loading time for 10K modules (25 level deep tree) using [vite-dev-server-perf](https://github.com/yyx990803/vite-dev-server-perf) for all minor versions from Vite 4.0. This is a good benchmark to measure the effect of Vite's bundle-less approach. Each module is a small TypeScript file with a counter and imports to other files in the tree, so this mostly measuring the time it takes to do the requests a separate modules. In Vite 4.0, loading 10K modules took 8 seconds on a M1 MAX. We had a breakthrough in [Vite 4.3 were we focused on performance](./announcing-vite4-3.md), and we were able to load them in 6.35 seconds. In Vite 5.1, we managed to do another performance leap. Vite is now serving the 10K modules in 5.35 seconds.
8686

8787
![Vite 10K Modules Loading time progression](/vite5-1-10K-modules-loading-time.png)
8888

@@ -113,7 +113,7 @@ The dev server had several incremental performance gains. A new middleware to sh
113113

114114
## Deprecations
115115

116-
We continue to reduce Vite's API surface where possible to make the project manintainable long term.
116+
We continue to reduce Vite's API surface where possible to make the project maintainable long term.
117117

118118
### Deprecated `as` option in `import.meta.glob`
119119

@@ -129,4 +129,4 @@ We are grateful to the [900 contributors to Vite Core](https://github.com/vitejs
129129

130130
## Acknowledgments
131131

132-
Vite 5.1 is possible thanks to our community of contributors, maintainers in the ecosystem, and the [Vite Team](/team). A shoutout the individuals and companies sponsoring Vite development. [StackBlitz](https://stackblitz.com/), [Nuxt Labs](https://nuxtlabs.com/), and [Astro](https://astro.build) for hiring Vite team members. And also to the sponsors on [Vite's GitHub Sponsors](https://github.com/sponsors/vitejs), [Vite's Open Collective](https://opencollective.com/vite), and [Evan You's GitHub Sponsors](https://github.com/sponsors/yyx990803).
132+
Vite 5.1 is possible thanks to our community of contributors, maintainers in the ecosystem, and the [Vite Team](/team). A shout out to the individuals and companies sponsoring Vite development. [StackBlitz](https://stackblitz.com/), [Nuxt Labs](https://nuxtlabs.com/), and [Astro](https://astro.build) for hiring Vite team members. And also to the sponsors on [Vite's GitHub Sponsors](https://github.com/sponsors/vitejs), [Vite's Open Collective](https://opencollective.com/vite), and [Evan You's GitHub Sponsors](https://github.com/sponsors/yyx990803).

config/build-options.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ type ResolveModulePreloadDependenciesFn = (
4848
4949
`resolveDependencies` 函数将为每个动态导入调用,同时带着一个它所依赖的 chunk 列表。并且它还会为每个在入口 HTML 文件中导入的 chunk 调用。 可以返回一个新的依赖关系数组,可能被过滤后变少了,也可能有更多依赖注入进来了,同时它们的路径也被修改过。`deps` 路径是相对于 `build.outDir` 的。若在注入该模块到 HTML head 时使用 `new URL(dep, import.meta.url)` 获取绝对路径,则对于 `hostType === 'js'`,允许返回一个相对于 `hostId` 的路径。
5050
51-
<!-- prettier-ignore-start -->
5251
```js twoslash
5352
/** @type {import('vite').UserConfig} */
5453
const config = {
54+
// prettier-ignore
5555
build: {
5656
// ---cut-before---
5757
modulePreload: {
@@ -63,7 +63,6 @@ modulePreload: {
6363
},
6464
}
6565
```
66-
<!-- prettier-ignore-end -->
6766

6867
解析得到的依赖路径可以再在之后使用 [`experimental.renderBuiltUrl`](../guide/build.md#advanced-base-options) 更改。
6968

config/server-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default defineConfig({
9090

9191
请注意,如果使用了非相对的 [基础路径 `base`](/config/shared-options.md#base),则必须在每个 key 值前加上该 `base`
9292

93-
继承自 [`http-proxy`](https://github.com/http-party/node-http-proxy#options)。完整选项详见 [此处](https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/middlewares/proxy.ts#L13)
93+
继承自 [`http-proxy`](https://github.com/http-party/node-http-proxy#options)。完整选项详见 [此处](https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/middlewares/proxy.ts#L13)需要注意的是,[与 http-proxy 不同](https://github.com/http-party/node-http-proxy/issues/1669)`changeOrigin` 选项会同时改变 host 和 origin 头以匹配目标。
9494

9595
在某些情况下,你可能也想要配置底层的开发服务器。(例如添加自定义的中间件到内部的 [connect](https://github.com/senchalabs/connect) 应用中)为了实现这一点,你需要编写你自己的 [插件](/guide/using-plugins.html) 并使用 [configureServer](/guide/api-plugin.html#configureserver) 函数。
9696

guide/api-javascript.md

+27
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,30 @@ async function loadConfigFromFile(
422422
```
423423

424424
手动通过 esbuild 加载一份 Vite 配置。
425+
426+
## `preprocessCSS`
427+
428+
- **实验性:** [提供反馈](https://github.com/vitejs/vite/discussions/13815)
429+
430+
**类型签名:**
431+
432+
```ts
433+
async function preprocessCSS(
434+
code: string,
435+
filename: string,
436+
config: ResolvedConfig,
437+
): Promise<PreprocessCSSResult>
438+
439+
interface PreprocessCSSResult {
440+
code: string
441+
map?: SourceMapInput
442+
modules?: Record<string, string>
443+
deps?: Set<string>
444+
}
445+
```
446+
447+
预处理 `.css``.scss``.sass``.less``.styl``.stylus` 文件,将它们转化为纯 CSS,这样就可以在浏览器中使用或者被其他工具解析了。这和 [内置的 CSS 预处理器](/guide/features#css-pre-processors) 很像,如果你使用了这个功能,则必须安装相应的预处理器。
448+
449+
使用哪个预处理器是根据 `filename` 的扩展名来推断的。如果 `filename``.module.{ext}` 结尾,那么它就会被推断为 [CSS module](https://github.com/css-modules/css-modules),返回的结果会包含一个 `modules` 对象,这个对象将原始的类名映射到转换后的类名。
450+
451+
需要注意的是,预处理不会解析 `url()``image-set()` 中的 URL

guide/api-plugin.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ Vite 插件也可以提供钩子来服务于特定的 Vite 目标。这些钩子
427427

428428
```js
429429
handleHotUpdate({ server, modules, timestamp }) {
430-
// 如果需要,也可使用 `server.ws.send` 来支持 Vite <5.1 版本
431-
server.hot.send({ type: 'full-reload' })
430+
server.ws.send({ type: 'full-reload' })
432431
// 手动使模块失效
433432
const invalidatedModules = new Set()
434433
for (const mod of modules) {
@@ -447,8 +446,7 @@ Vite 插件也可以提供钩子来服务于特定的 Vite 目标。这些钩子
447446

448447
```js
449448
handleHotUpdate({ server }) {
450-
// 如果需要,也可使用 `server.ws.send` 来支持 Vite <5.1 版本
451-
server.hot.send({
449+
server.ws.send({
452450
type: 'custom',
453451
event: 'special-update',
454452
data: {}
@@ -555,7 +553,7 @@ Vite 暴露了 [`@rollup/pluginutils` 的 `createFilter`](https://github.com/rol
555553

556554
### 服务端到客户端 {#server-to-client}
557555

558-
在插件一侧,我们可以使用 `server.hot.send`(自 Vite 5.1 起)或 `server.ws.send` 去给所有客户端广播事件
556+
在插件一侧,我们可以使用 `server.ws.send` 来向客户端广播事件
559557

560558
```js
561559
// vite.config.js
@@ -564,9 +562,8 @@ export default defineConfig({
564562
{
565563
// ...
566564
configureServer(server) {
567-
// 示例:等待客户端连接后再发送消息
568-
server.hot.on('connection', () => {
569-
server.hot.send('my:greetings', { msg: 'hello' })
565+
server.ws.on('connection', () => {
566+
server.ws.send('my:greetings', { msg: 'hello' })
570567
})
571568
},
572569
},
@@ -602,7 +599,7 @@ if (import.meta.hot) {
602599
}
603600
```
604601

605-
然后使用 `server.hot.on`(自 Vite 5.1 起) 或 `server.ws.on` 并在服务端监听这些事件:
602+
然后使用 `server.ws.on` 并在服务端监听这些事件:
606603

607604
```js
608605
// vite.config.js
@@ -611,7 +608,7 @@ export default defineConfig({
611608
{
612609
// ...
613610
configureServer(server) {
614-
server.hot.on('my:from-client', (data, client) => {
611+
server.ws.on('my:from-client', (data, client) => {
615612
console.log('Message from client:', data.msg) // Hey!
616613
// reply only to the client (if needed)
617614
client.send('my:ack', { msg: 'Hi! I got your message!' })

guide/build.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ dist/my-lib.umd.cjs 0.30 kB / gzip: 0.16 kB
236236

237237
单个静态的 [基础路径](#public-base-path) 在这种场景中就不够用了。Vite 在构建时为更高级的基础路径选项提供了实验性支持,可以使用 `experimental.renderBuiltUrl`
238238

239-
<!-- prettier-ignore-start -->
240239
```ts twoslash
241240
import type { UserConfig } from 'vite'
241+
// prettier-ignore
242242
const config: UserConfig = {
243243
// ---cut-before---
244244
experimental: {
@@ -253,14 +253,13 @@ experimental: {
253253
// ---cut-after---
254254
}
255255
```
256-
<!-- prettier-ignore-end -->
257256

258257
如果 hash 后的资源和公共文件没有被部署在一起,可以根据该函数的第二个参数 `context` 上的字段 `type` 分别定义各个资源组的选项:
259258

260-
<!-- prettier-ignore-start -->
261259
```ts twoslash
262260
import type { UserConfig } from 'vite'
263261
import path from 'node:path'
262+
// prettier-ignore
264263
const config: UserConfig = {
265264
// ---cut-before---
266265
experimental: {
@@ -277,6 +276,5 @@ experimental: {
277276
// ---cut-after---
278277
}
279278
```
280-
<!-- prettier-ignore-end -->
281279

282280
请注意,传递的 `filename` 是一个已解码的 URL,如果函数返回了一个 URL 字符串,那么它也应该是已解码的。当 Vite 渲染 URL 时会自动处理编码。如果返回的是一个带有 `runtime` 的对象,就需要在必要的地方自行处理编码,因为运行时的代码将会按照原样呈现。

guide/env-and-mode.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ interface ImportMeta {
9494
}
9595
```
9696
97-
如果你的代码依赖于浏览器环境的类型,比如 [DOM](https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts) 和 [WebWorker](https://github.com/microsoft/TypeScript/blob/main/lib/lib.webworker.d.ts),你可以在 `tsconfig.json` 中修改 [lib](https://www.typescriptlang.org/tsconfig#lib) 字段来获取类型支持。
97+
如果你的代码依赖于浏览器环境的类型,比如 [DOM](https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts) 和 [WebWorker](https://github.com/microsoft/TypeScript/blob/main/src/lib/webworker.generated.d.ts),你可以在 `tsconfig.json` 中修改 [lib](https://www.typescriptlang.org/tsconfig#lib) 字段来获取类型支持。
9898
9999
```json
100100
{

guide/features.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export default defineConfig({
211211

212212
Vite 通过 `postcss-import` 预配置支持了 CSS `@import` 内联,Vite 的路径别名也遵从 CSS `@import`。换句话说,所有 CSS `url()` 引用,即使导入的文件在不同的目录中,也总是自动变基,以确保正确性。
213213

214-
Sass 和 Less 文件也支持 `@import` 别名和 URL 变基(具体请参阅 [CSS Pre-processors](#css-pre-processors))。
214+
Sass 和 Less 文件也支持 `@import` 别名和 URL 变基(具体请参阅 [CSS 预处理器](#css-pre-processors))。
215215

216216
### PostCSS {#postcss}
217217

guide/index.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Vite 还提供了强大的扩展性,可通过其 [插件 API](./api-plugin)
4444
## 搭建第一个 Vite 项目 {#scaffolding-your-first-vite-project}
4545

4646
::: tip 兼容性注意
47-
Vite 需要 [Node.js](https://nodejs.org/en/) 版本 18+20+。然而,有些模板需要依赖更高的 Node 版本才能正常运行,当你的包管理器发出警告时,请注意升级你的 Node 版本。
47+
Vite 需要 [Node.js](https://nodejs.org/en/) 版本 18+20+。然而,有些模板需要依赖更高的 Node 版本才能正常运行,当你的包管理器发出警告时,请注意升级你的 Node 版本。
4848
:::
4949

5050
::: code-group
@@ -87,6 +87,8 @@ bun create vite my-vue-app --template vue
8787

8888
查看 [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite) 以获取每个模板的更多细节:`vanilla``vanilla-ts`, `vue`, `vue-ts``react``react-ts``react-swc``react-swc-ts``preact``preact-ts``lit``lit-ts``svelte``svelte-ts``solid``solid-ts``qwik``qwik-ts`
8989

90+
你可以使用 `.` 作为项目名称,在当前目录中创建项目脚手架。
91+
9092
## 社区模板 {#community-templates}
9193

9294
create-vite 是一个快速生成主流框架基础模板的工具。查看 Awesome Vite 仓库的 [社区维护模板](https://github.com/vitejs/awesome-vite#templates),里面包含各种工具和不同框架的模板。
@@ -103,6 +105,44 @@ npm install
103105
npm run dev
104106
```
105107

108+
## 手动安装 {#manual-installation}
109+
110+
在你的项目中,可以用以下方法来安装 `vite` 命令行工具:
111+
112+
::: code-group
113+
114+
```bash [NPM]
115+
$ npm install -D vite
116+
```
117+
118+
```bash [Yarn]
119+
$ yarn add -D vite
120+
```
121+
122+
```bash [PNPM]
123+
$ pnpm add -D vite
124+
```
125+
126+
```bash [Bun]
127+
$ bun add -D vite
128+
```
129+
130+
:::
131+
132+
并创建一个像这样的 `index.html` 文件:
133+
134+
```html
135+
<p>Hello Vite!</p>
136+
```
137+
138+
然后在终端中运行 `vite`
139+
140+
```bash
141+
vite
142+
```
143+
144+
就可以在 `http://localhost:5173` 上访问 `index.html`
145+
106146
## `index.html` 与项目根目录 {#index-html-and-project-root}
107147

108148
你可能已经注意到,在一个 Vite 项目中,`index.html` 在项目最外层而不是在 `public` 文件夹内。这是有意而为之的:在开发期间 Vite 是一个服务器,而 `index.html` 是该 Vite 项目的入口文件。

0 commit comments

Comments
 (0)