@@ -71,18 +71,12 @@ export type { T }
71
71
72
72
- [ TypeScript 文档] ( https://www.typescriptlang.org/tsconfig#useDefineForClassFields )
73
73
74
- 从 Vite v2.5.0 开始, 如果 TypeScript 的 target 是 ` ESNext ` 或 ` ES2022 ` 及更新版本,此选项默认值则为 ` true ` 。这与 [ ` tsc ` v4 .3.2 及以后版本的行为] ( https://github.com/microsoft/TypeScript/pull/42663 ) 一致。这也是标准的 ECMAScript 的运行时行为 。
74
+ 如果 TypeScript 的 target 是 ` ES2022 ` 或更高版本,包括 ` ESNext ` ,那么默认值将为 ` true ` 。这与 [ TypeScript 4 .3.2 及以后版本的行为] ( https://github.com/microsoft/TypeScript/pull/42663 ) 保持一致 。
75
75
76
76
若设了其他 TypeScript target,则本项会默认为 ` false ` .
77
77
78
- 但对于那些习惯其他编程语言或旧版本 TypeScript 的开发者来说,这可能是违反直觉的。
79
- 你可以参阅 [ TypeScript 3.7 发布日志] ( https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier ) 中了解更多关于如何兼容的信息。
80
-
81
78
如果你正在使用一个严重依赖 class fields 的库,请注意该库对此选项的预期设置。
82
-
83
- 大多数库都希望 ` "useDefineForClassFields": true ` ,如 [ MobX] ( https://mobx.js.org/installation.html#use-spec-compliant-transpilation-for-class-properties ) 。
84
-
85
- 但是有几个库还没有兼容这个新的默认值,其中包括 [ ` lit-element ` ] ( https://github.com/lit/lit-element/issues/1030 ) 。如果遇到这种情况,请将 ` useDefineForClassFields ` 设置为 ` false ` 。
79
+ 虽然大多数库期望 ` "useDefineForClassFields": true ` ,但如果你的库不支持它,你可以明确地将 ` useDefineForClassFields ` 设置为 ` false ` 。
86
80
87
81
#### ` target ` {#target}
88
82
@@ -124,20 +118,26 @@ Vite 默认的类型定义是写给它的 Node.js API 的。要将其补充到
124
118
/// <reference types = " vite/client" />
125
119
```
126
120
121
+ ::: details 使用 ` compilerOptions.types `
122
+
127
123
或者,你也可以将 ` vite/client ` 添加到 ` tsconfig.json ` 中的 ` compilerOptions.types ` 下:
128
124
129
125
``` json [tsconfig.json]
130
126
{
131
127
"compilerOptions" : {
132
- "types" : [" vite/client" ]
128
+ "types" : [" vite/client" , " some-other-global-lib " ]
133
129
}
134
130
}
135
131
```
136
132
137
- 这将会提供以下类型定义补充:
133
+ 需要注意的是,如果指定了 [ ` compilerOptions.types ` ] ( https://www.typescriptlang.org/tsconfig#types ) ,则只有这些包会被包含在全局作用域内(而不是所有的“@types ”包)。
134
+
135
+ :::
136
+
137
+ ` vite/client ` 会提供以下类型定义补充:
138
138
139
139
- 资源导入 (例如:导入一个 ` .svg ` 文件)
140
- - ` import.meta.env ` 上 Vite 注入的 [ 常量变量 ] ( ./env-and-mode#env-variables ) 的类型定义
140
+ - ` import.meta.env ` 上 Vite 注入的 [ 常量 ] ( ./env-and-mode#env-variables ) 的类型定义
141
141
- ` import.meta.hot ` 上的 [ HMR API] ( ./api-hmr ) 类型定义
142
142
143
143
::: tip
@@ -204,22 +204,24 @@ HTML 文件位于 Vite 项目的[最前端和中心](/guide/#index-html-and-proj
204
204
205
205
要退出对某些元素的 HTML 处理,可以在元素上添加 ` vite-ignore ` 属性,这在引用外部 assets 或 CDN 时非常有用。
206
206
207
- ## Vue {#vue}
207
+ ## 框架支持 {#frameworks}
208
+
209
+ 所有现代框架都已和 Vite 集成。大多数框架插件由各自的框架团队维护,唯有官方的 Vue 和 React Vite 插件由 Vite 组织维护。
208
210
209
- Vite 为 Vue 提供第一优先级支持:
211
+ - Vue 支持:[ @vitejs/plugin-vue ] ( https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue )
212
+ - Vue JSX 支持:[ @vitejs/plugin-vue-jsx ] ( https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx )
213
+ - React 支持:[ @vitejs/plugin-react ] ( https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react )
214
+ - React 使用 SWC 的支持:[ @vitejs/plugin-react-swc ] ( https://github.com/vitejs/vite-plugin-react-swc )
210
215
211
- - Vue 3 单文件组件支持:[ @vitejs/plugin-vue ] ( https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue )
212
- - Vue 3 JSX 支持:[ @vitejs/plugin-vue-jsx ] ( https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx )
213
- - Vue 2.7 SFC 支持:[ @vitejs/plugin-vue2 ] ( https://github.com/vitejs/vite-plugin-vue2 )
214
- - Vue 2.7 JSX 支持:[ @vitejs/plugin-vue2-jsx ] ( https://github.com/vitejs/vite-plugin-vue2-jsx )
216
+ 查看 [ 插件指南] ( /plugins/ ) 了解更多信息。
215
217
216
218
## JSX {#jsx}
217
219
218
220
` .jsx ` 和 ` .tsx ` 文件同样开箱即用。JSX 的转译同样是通过 [ esbuild] ( https://esbuild.github.io ) 。
219
221
220
- Vue 用户应使用官方提供的 [ @vitejs/plugin-vue-jsx ] ( https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx ) 插件,它提供了 Vue 3 特性的支持 ,包括 HMR,全局组件解析,指令和插槽。
222
+ 你选择的框架已经可以开箱即用地配置 JSX(例如, Vue 用户应使用官方的 [ @vitejs/plugin-vue-jsx ] ( https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx ) 插件,它提供了 Vue 3 特定的功能 ,包括 HMR,全局组件解析,指令和插槽) 。
221
223
222
- 如果不是在 React 或 Vue 中使用 JSX,自定义的 ` jsxFactory ` 和 ` jsxFragment ` 可以使用 [ ` esbuild ` 选项] ( /config/shared-options.md#esbuild ) 进行配置。例如对 Preact:
224
+ 如果你使用自己的框架运行 JSX,可以使用 [ ` esbuild ` 选项] ( /config/shared-options.md#esbuild ) 来配置自定义的 ` jsxFactory ` 和 ` jsxFragment ` 。例如, Preact 插件会使用 :
223
225
224
226
``` js twoslash [vite.config.js]
225
227
import { defineConfig } from ' vite'
0 commit comments