Skip to content

Commit dd47f6e

Browse files
Merge pull request #463 from vitejs/release/2.9.8
2 parents 9f46c98 + fd32f07 commit dd47f6e

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

config/index.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,29 @@ export default defineConfig(({ command, mode }) => {
9090
export default defineConfig(async ({ command, mode }) => {
9191
const data = await asyncFunction()
9292
return {
93-
// 构建模式所需的特有配置
93+
// vite 配置
9494
}
9595
})
9696
```
9797

98-
### Environment Variables {#environment-variables}
98+
### 环境变量 {#environment-variables}
9999

100-
Vite 默认是不加载 `.env` 文件的,因为这些文件需要在执行完 Vite 配置后才能确定加载哪一个,举个例子,`root``envDir` 选项会影响加载行为。不过当你的确需要时,你可以使用 Vite 导出的 `loadEnv` 函数来加载指定的 `.env` 文件
100+
环境变量通常可以从 `process.env` 获得。
101+
102+
注意 Vite 默认是不加载 `.env` 文件的,因为这些文件需要在执行完 Vite 配置后才能确定加载哪一个,举个例子,`root``envDir` 选项会影响加载行为。不过当你的确需要时,你可以使用 Vite 导出的 `loadEnv` 函数来加载指定的 `.env` 文件
101103

102104
```js
103105
import { defineConfig, loadEnv } from 'vite'
104106

105107
export default defineConfig(({ command, mode }) => {
106108
// 根据当前工作目录中的 `mode` 加载 .env 文件
107-
const env = loadEnv(mode, process.cwd())
109+
// 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
110+
const env = loadEnv(mode, process.cwd(), '')
108111
return {
109-
// 构建特定配置
112+
// vite config
113+
define: {
114+
__APP_ENV__: env.APP_ENV
115+
}
110116
}
111117
})
112118
```
@@ -298,7 +304,11 @@ export default defineConfig(({ command, mode }) => {
298304

299305
- **类型:** `string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] })`
300306

301-
内联的 PostCSS 配置(格式同 `postcss.config.js`),或者一个(默认基于项目根目录的)自定义的 PostCSS 配置路径。其路径搜索是通过 [postcss-load-config](https://github.com/postcss/postcss-load-config) 实现的,并且只加载支持的配置文件名称。
307+
内联的 PostCSS 配置(格式同 `postcss.config.js`),或者一个(默认基于项目根目录的)自定义的 PostCSS 配置路径。
308+
309+
对内联的 POSTCSS 配置,它期望接收与 `postcss.config.js` 一致的格式。但对于 `plugins` 属性有些特别,只接收使用 [数组格式](https://github.com/postcss/postcss-load-config/blob/main/README.md#array)
310+
311+
搜索是使用 [postcss-load-config](https://github.com/postcss/postcss-load-config) 完成的,只有被支持的文件名才会被加载。
302312

303313
注意:如果提供了该内联配置,Vite 将不会搜索其他 PostCSS 配置源。
304314

@@ -694,7 +704,7 @@ createServer()
694704
```js
695705
export default defineConfig({
696706
server: {
697-
origin: 'http://127.0.0.1:8080/'
707+
origin: 'http://127.0.0.1:8080'
698708
}
699709
})
700710
```

guide/api-hmr.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@ Vite 通过特殊的 `import.meta.hot` 对象暴露手动 HMR API。
1010

1111
```ts
1212
interface ImportMeta {
13-
readonly hot?: {
14-
readonly data: any
13+
readonly hot?: ViteHotContext
14+
}
15+
16+
interface ViteHotContext {
17+
readonly data: any
1518

16-
accept(): void
17-
accept(cb: (mod: any) => void): void
18-
accept(dep: string, cb: (mod: any) => void): void
19-
accept(deps: string[], cb: (mods: any[]) => void): void
19+
accept(): void
20+
accept(cb: (mod: any) => void): void
21+
accept(dep: string, cb: (mod: any) => void): void
22+
accept(deps: readonly string[], cb: (mods: any[]) => void): void
2023

21-
prune(cb: () => void): void
22-
dispose(cb: (data: any) => void): void
23-
decline(): void
24-
invalidate(): void
24+
dispose(cb: (data: any) => void): void
25+
decline(): void
26+
invalidate(): void
2527

26-
on(event: string, cb: (...args: any[]) => void): void
27-
}
28+
// `InferCustomEventPayload` provides types for built-in Vite events
29+
on<T extends string>(
30+
event: T,
31+
cb: (payload: InferCustomEventPayload<T>) => void
32+
): void
33+
send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
2834
}
2935
```
3036

guide/features.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export type { T }
5353

5454
你必须在 `tsconfig.json` 中的 `compilerOptions` 下设置 `"isolatedModules": true`。如此做,TS 会警告你不要使用隔离(isolated)转译的功能。
5555

56+
However, some libraries (e.g. [`vue`](https://github.com/vuejs/core/issues/1228)) don't work well with `"isolatedModules": true`. You can use `"skipLibCheck": true` to temporarily suppress the errors until it is fixed upstream.
57+
5658
#### `useDefineForClassFields`
5759

5860
从 Vite v2.5.0 开始,如果 TypeScript 的 target 是 `ESNext`,此选项默认值则为 `true`。这与 [`tsc` v4.3.2 及以后版本的行为](https://github.com/microsoft/TypeScript/pull/42663) 一致。这也是标准的 ECMAScript 的运行时行为。
@@ -185,7 +187,7 @@ document.getElementById('foo').className = applyColor
185187

186188
### CSS 预处理器 {#css-pre-processors}
187189

188-
由于 Vite 的目标仅为现代浏览器,因此建议使用原生 CSS 变量和实现 CSSWG 草案的 PostCSS 插件(例如 [postcss-nesting](https://github.com/jonathantneal/postcss-nesting))来编写简单的、符合未来标准的 CSS。
190+
由于 Vite 的目标仅为现代浏览器,因此建议使用原生 CSS 变量和实现 CSSWG 草案的 PostCSS 插件(例如 [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting))来编写简单的、符合未来标准的 CSS。
189191

190192
话虽如此,但 Vite 也同时提供了对 `.scss`, `.sass`, `.less`, `.styl``.stylus` 文件的内置支持。没有必要为它们安装特定的 Vite 插件,但必须安装相应的预处理器依赖:
191193

plugins/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Vite 旨在为常见的 web 开发工作提供开箱即用的支持。在搜索一个 Vite 或 Rollup 兼容插件之前,请先查看 [功能指引](../guide/features.md)。很多场景下,在 Rollup 项目中需要添加插件,而在 Vite 中已经内建支持了。
55
:::
66

7+
查看 [使用插件](../guide/using-plugins) 一章获取如何插件使用方式的更多信息。
8+
79
## 官方插件 {#official-plugins}
810

911
### [@vitejs/plugin-vue](https://github.com/vitejs/vite/tree/main/packages/plugin-vue) {#vitejsplugin-vue}

0 commit comments

Comments
 (0)