Skip to content

Commit bda54f6

Browse files
authored
docs(cn): update with main stream
release v4.2.1
2 parents 056f051 + bdd1bde commit bda54f6

22 files changed

+167
-32
lines changed

.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default defineConfig({
3838
en: { label: 'English', link: 'https://vitejs.dev' },
3939
ja: { label: '日本語', link: 'https://ja.vitejs.dev' },
4040
es: { label: 'Español', link: 'https://es.vitejs.dev' },
41+
pt: { label: 'Português', link: 'https://pt.vitejs.dev' },
4142
},
4243

4344
vue: {

_data/team.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const core = [
6666
title: 'Developer',
6767
org: 'Vue.js',
6868
orgLink: 'https://vuejs.org/',
69-
desc: 'Vite/Vite core team member. Full-time open sourcerer.',
69+
desc: 'Vue/Vite core team member. Full-time open sourcerer.',
7070
links: [
7171
{ icon: 'github', link: 'https://github.com/sodatea' },
7272
{ icon: 'twitter', link: 'https://twitter.com/haoqunjiang' },

blog/announcing-vite2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ sidebar: false
44

55
# Vite 2.0 发布了 {#announcing-vite-2-0}
66

7+
_February 16, 2021_ - Check out the [Vite 3.0 announcement](./announcing-vite3.md)
8+
79
<p style="text-align:center">
810
<img src="/logo.svg" style="height:200px">
911
</p>

blog/announcing-vite3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ head:
2323

2424
# Vite 3.0 is out!
2525

26+
_July 23, 2022_ - Check out the [Vite 4.0 announcement](./announcing-vite4.md)
27+
2628
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.
2729

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

blog/announcing-vite4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ head:
2323

2424
# Vite 4.0 is out!
2525

26+
_December 9, 2022_
27+
2628
Vite 3 [was released](./announcing-vite3.md) five months ago. npm downloads per week have gone from 1 million to 2.5 million since then. The ecosystem has matured too, and continues to grow. In this year's [Jamstack Conf survey](https://twitter.com/vite_js/status/1589665610119585793), usage among the community jumped from 14% to 32% while keeping a high 9.7 satisfaction score. We saw the stable releases of [Astro 1.0](https://astro.build/), [Nuxt 3](https://v3.nuxtjs.org/), and other Vite-powered frameworks that are innovating and collaborating: [SvelteKit](https://kit.svelte.dev/), [Solid Start](https://www.solidjs.com/blog/introducing-solidstart), [Qwik City](https://qwik.builder.io/qwikcity/overview/). Storybook announced first-class support for Vite as one of its main features for [Storybook 7.0](https://storybook.js.org/blog/first-class-vite-support-in-storybook/). Deno now [supports Vite](https://www.youtube.com/watch?v=Zjojo9wdvmY). [Vitest](https://vitest.dev) adoption is exploding, it will soon represent half of Vite's npm downloads. Nx is also investing in the ecosystem, and [officially supports Vite](https://nx.dev/packages/vite).
2729

2830
[![Vite 4 Ecosystem](/ecosystem-vite4.png)](https://viteconf.org/2022/replay)

config/build-options.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
另一个特殊值是 “esnext” —— 即假设有原生动态导入支持,并且将会转译得尽可能小:
1212

13-
- 如果 [`build.minify`](#build-minify) 选项为 `'terser'``'esnext'` 将会强制降级为 `'es2021'`
13+
- 如果 [`build.minify`](#build-minify) 选项为 `'terser'`并且安装的 Terser 版本小于 5.16.0,`'esnext'` 将会强制降级为 `'es2021'`
1414
- 其他情况下将完全不会执行转译。
1515

1616
转换过程将会由 esbuild 执行,并且此值应该是一个合法的 [esbuild 目标选项](https://esbuild.github.io/api/#target)。自定义目标也可以是一个 ES 版本(例如:`es2015`)、一个浏览器版本(例如:`chrome58`)或是多个目标组成的一个数组。
@@ -78,7 +78,7 @@ modulePreload: {
7878
- **类型:** `string`
7979
- **默认:** `assets`
8080
81-
指定生成静态资源的存放路径(相对于 `build.outDir`)。
81+
指定生成静态资源的存放路径(相对于 `build.outDir`)。在 [库模式](/guide/build#library-mode) 下不能使用。
8282
8383
## build.assetsInlineLimit {#build-assetsinlinelimit}
8484
@@ -106,7 +106,7 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含它们所
106106
如果指定了 `build.lib``build.cssCodeSplit` 会默认为 `false`
107107
:::
108108
109-
## build.cssTarget
109+
## build.cssTarget {#build-csstarget}
110110
111111
- **类型:** `string | string[]`
112112
- **默认值:** 与 [`build.target`](/config/#build-target) 一致
@@ -117,6 +117,13 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含它们所
117117
最直观的示例是当你要兼容的场景是安卓微信中的 webview 时,它支持大多数现代的 JavaScript 功能,但并不支持 [CSS 中的 `#RGBA` 十六进制颜色符号](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgb_colors)。
118118
这种情况下,你需要将 `build.cssTarget` 设置为 `chrome61`,以防止 vite 将 `rgba()` 颜色转化为 `#RGBA` 十六进制符号的形式。
119119
120+
## build.cssMinify {#build-cssminify}
121+
122+
- **类型:** `boolean`
123+
- **默认:** 与 [`build.minify`](#build-minify) 一致
124+
125+
此选项允许用户覆盖 CSS 最小化压缩的配置,而不是使用默认的 `build.minify`,这样你就可以单独配置 JS 和 CSS 的最小化压缩方式。Vite 使用 `esbuild` 来最小化 CSS。
126+
120127
## build.sourcemap {#build-sourcemap}
121128
122129
- **类型:** `boolean | 'inline' | 'hidden'`
@@ -229,7 +236,7 @@ npm add -D terser
229236
- **类型:** `number`
230237
- **默认:** `500`
231238
232-
规定触发警告的 chunk 大小。(以 kbs 为单位)
239+
规定触发警告的 chunk 大小。(以 kbs 为单位)。它将与未压缩的 chunk 大小进行比较,因为 [JavaScript 大小本身与执行时间相关](https://v8.dev/blog/cost-of-javascript-2019)。
233240
234241
## build.watch {#build-watch}
235242

config/dep-optimization-options.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ export default defineConfig({
5151
- **类型:** `boolean`
5252

5353
设置为 `true` 可以强制依赖预构建,而忽略之前已经缓存过的、已经优化过的依赖。
54+
55+
## optimizeDeps.disabled {#optimizedeps-disabled}
56+
57+
- **实验性**
58+
- **类型:** `boolean | 'build' | 'dev'`
59+
- **默认:** `'build'`
60+
61+
禁用依赖优化,值为 `true` 将在构建和开发期间均禁用优化器。传 `'build'``'dev'` 将仅在其中一种模式下禁用优化器。默认情况下,仅在开发阶段启用依赖优化。
62+
63+
:::warning
64+
在构建模式下依赖优化是 **实验性** 的。如果开启此项,那么它将消除开发与构建最终产物之间的最明显的区别之一。[`@rollup/plugin-commonjs`](https://github.com/rollup/plugins/tree/master/packages/commonjs) 在此处将不再需要,因为 esbuild 会将纯 CJS 依赖转换为 ESM。
65+
66+
如果你想尝试该构建策略,你可以使用 `optimizeDeps.disabled: false``@rollup/plugin-commonjs` 可以通过设置 `build.commonjsOptions: { include: [] }` 来移除。
67+
:::

config/server-options.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export default defineConfig({
312312

313313
- **类型:** `string`
314314

315-
用于定义开发调试阶段生成资产的 origin。
315+
用于定义开发调试阶段生成资源的 origin。
316316

317317
```js
318318
export default defineConfig({
@@ -321,3 +321,30 @@ export default defineConfig({
321321
},
322322
})
323323
```
324+
325+
## server.sourcemapIgnoreList {#server-sourcemapignorelist}
326+
327+
- **类型:** `false | (sourcePath: string, sourcemapPath: string) => boolean`
328+
- **默认:** `(sourcePath) => sourcePath.includes('node_modules')`
329+
330+
是否忽略服务器 sourcemap 中的源文件,用于填充 [`x_google_ignoreList` source map 扩展](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension)
331+
332+
对开发服务器来说 `server.sourcemapIgnoreList` 等价于 [`build.rollupOptions.output.sourcemapIgnoreList`](https://rollupjs.org/configuration-options/#output-sourcemapignorelist)。两个配置选项之间的区别在于,rollup 函数使用相对路径调用 `sourcePath`,而 `server.sourcemapIgnoreList` 使用绝对路径调用。在开发过程中,大多数模块的映射和源文件位于同一个文件夹中,因此 `sourcePath` 的相对路径就是文件名本身。在这些情况下,使用绝对路径更加方便。
333+
334+
默认情况下,它会排除所有包含 `node_modules` 的路径。你可以传递 `false` 来禁用此行为,或者为了获得完全的控制,可以传递一个函数,该函数接受源路径和 sourcemap 的路径,并返回是否忽略源路径。
335+
336+
```js
337+
export default defineConfig({
338+
server: {
339+
// 这是默认值,它将把所有路径中含有 node_modules 的文件
340+
// 添加到忽略列表中。
341+
sourcemapIgnoreList(sourcePath, sourcemapPath) {
342+
return sourcePath.includes('node_modules')
343+
}
344+
}
345+
};
346+
```
347+
348+
::: tip 注意
349+
需要单独设置 [`server.sourcemapIgnoreList`](#server-sourcemapignorelist) 和 [`build.rollupOptions.output.sourcemapIgnoreList`](https://rollupjs.org/configuration-options/#output-sourcemapignorelist)。`server.sourcemapIgnoreList` 是一个仅适用于服务端的配置,并不从定义好的 rollup 选项中获得其默认值。
350+
:::

config/shared-options.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ Vite 有一个“允许的情景”列表,并且会匹配列表中第一个情
188188
## css.modules {#css-modules}
189189

190190
- **类型:**
191-
192191
```ts
193192
interface CSSModulesOptions {
194193
scopeBehaviour?: 'global' | 'local'
@@ -227,7 +226,15 @@ interface CSSModulesOptions {
227226

228227
- **类型:** `Record<string, object>`
229228

230-
指定传递给 CSS 预处理器的选项。文件扩展名用作选项的键,例如:
229+
指定传递给 CSS 预处理器的选项。文件扩展名用作选项的键。每个预处理器支持的选项可以在它们各自的文档中找到:
230+
231+
- `sass`/`scss` - [选项](https://sass-lang.com/documentation/js-api/interfaces/LegacyStringOptions)
232+
- `less` - [选项](https://lesscss.org/usage/#less-options)
233+
- `styl`/`stylus` - 仅支持 [`define`](https://stylus-lang.com/docs/js.html#define-name-node),可以作为对象传递。
234+
235+
所有预处理器选项还支持 `additionalData` 选项,可以用于为每个样式内容注入额外代码。
236+
237+
示例:
231238

232239
```js
233240
export default defineConfig({
@@ -236,8 +243,13 @@ export default defineConfig({
236243
scss: {
237244
additionalData: `$injectedColor: orange;`,
238245
},
246+
less: {
247+
math: 'parens-division',
248+
},
239249
styl: {
240-
additionalData: `$injectedColor ?= orange`,
250+
define: {
251+
$specialColor: new stylus.nodes.RGBA(51, 197, 255, 1),
252+
},
241253
},
242254
},
243255
},
@@ -326,6 +338,40 @@ export default defineConfig({
326338

327339
调整控制台输出的级别,默认为 `'info'`
328340

341+
## customLogger {#customlogger}
342+
343+
- **类型:**
344+
```ts
345+
interface Logger {
346+
info(msg: string, options?: LogOptions): void
347+
warn(msg: string, options?: LogOptions): void
348+
warnOnce(msg: string, options?: LogOptions): void
349+
error(msg: string, options?: LogErrorOptions): void
350+
clearScreen(type: LogType): void
351+
hasErrorLogged(error: Error | RollupError): boolean
352+
hasWarned: boolean
353+
}
354+
```
355+
356+
使用自定义 logger 记录消息。可以使用 Vite 的 `createLogger` API 获取默认的 logger 并对其进行自定义,例如,更改消息或过滤掉某些警告。
357+
358+
```js
359+
import { createLogger, defineConfig } from 'vite'
360+
361+
const logger = createLogger()
362+
const loggerWarn = logger.warn
363+
364+
logger.warn = (msg, options) => {
365+
// 忽略空 CSS 文件的警告
366+
if (msg.includes('vite:css') && msg.includes(' is empty')) return
367+
loggerWarn(msg, options)
368+
}
369+
370+
export default defineConfig({
371+
customLogger: logger,
372+
})
373+
```
374+
329375
## clearScreen {#clearscreen}
330376

331377
- **类型:** `boolean`
@@ -351,6 +397,15 @@ export default defineConfig({
351397

352398
:::warning 安全注意事项
353399
`envPrefix` 不应被设置为空字符串 `''`,这将暴露你所有的环境变量,导致敏感信息的意外泄漏。 检测到配置为 `''` 时 Vite 将会抛出错误.
400+
401+
如果你想暴露一个不含前缀的变量,可以使用 [define](#define) 选项:
402+
403+
```js
404+
define: {
405+
'import.meta.env.ENV_VARIABLE': JSON.stringify(process.env.ENV_VARIABLE)
406+
}
407+
```
408+
354409
:::
355410

356411
## appType {#apptype}

config/worker-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## worker.format
66

77
- **类型:** `'es' | 'iife'`
8-
- **默认:** `iife`
8+
- **默认:** `'iife'`
99

1010
worker 打包时的输出类型。
1111

0 commit comments

Comments
 (0)