Skip to content

Commit 7fd93de

Browse files
committed
docs(cn): translate comments
1 parent 4ab52a3 commit 7fd93de

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

guide/api-javascript.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JavaScript API {#javascript-api}
22

3-
Vite 的 JavaScript API 是完全类型化的,我们推荐使用 TypeScript 或者在 VS Code 中启用 JS 类型检查来利用智能提示和类型校验
3+
Vite 的 JavaScript API 是完全类型化的,我们推荐使用 TypeScript 或者在 VS Code 中启用 JS 类型检查来利用智能提示和类型签名
44

55
## `createServer` {#createserver}
66

@@ -186,7 +186,7 @@ interface ViteDevServer {
186186

187187
## `build` {#build}
188188

189-
**类型校验**
189+
**类型签名**
190190

191191
```ts
192192
async function build(
@@ -281,7 +281,7 @@ interface PreviewServer {
281281

282282
## `resolveConfig` {#resolveconfig}
283283

284-
**类型校验**
284+
**类型签名**
285285

286286
```ts
287287
async function resolveConfig(

guide/api-vite-runtime.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ export class ViteRuntime {
2222
private debug?: ViteRuntimeDebugger,
2323
) {}
2424
/**
25-
* URL to execute. Accepts file path, server path, or id relative to the root.
25+
* 要执行的 URL。可以是文件路径、服务器路径,或者是相对于根目录的 id。
2626
*/
2727
public async executeUrl<T = any>(url: string): Promise<T>
2828
/**
29-
* Entry point URL to execute. Accepts file path, server path or id relative to the root.
30-
* In the case of a full reload triggered by HMR, this is the module that will be reloaded.
31-
* If this method is called multiple times, all entry points will be reloaded one at a time.
29+
* 执行的入口文件 URL。可以是文件路径、服务器路径,或者是相对于根目录的 id。
30+
* 如果是由 HMR 触发的全面重载,那么这就是将要被重载的模块。
31+
* 如果这个方法被多次调用,所有的入口文件都将逐一被重新加载。
3232
*/
3333
public async executeEntrypoint<T = any>(url: string): Promise<T>
3434
/**
35-
* Clear all caches including HMR listeners.
35+
* 清除所有缓存,包括 HMR 监听器。
3636
*/
3737
public clearCache(): void
3838
/**
39-
* Clears all caches, removes all HMR listeners, and resets source map support.
40-
* This method doesn't stop the HMR connection.
39+
* 清除所有缓存,移除所有 HMR 监听器,并重置 sourcemap 支持。
40+
* 此方法不会停止 HMR 连接。
4141
*/
4242
public async destroy(): Promise<void>
4343
/**
44-
* Returns `true` if the runtime has been destroyed by calling `destroy()` method.
44+
* 如果通过调用 `destroy()` 方法销毁了运行时,则返回 `true`。
4545
*/
4646
public isDestroyed(): boolean
4747
}
@@ -67,7 +67,7 @@ const runtime = new ViteRuntime(
6767
{
6868
root,
6969
fetchModule,
70-
// you can also provide hmr.connection to support HMR
70+
// 你也可以提供 hmr.connection 以支持 HMR
7171
},
7272
new ESModulesRunner(),
7373
)
@@ -80,42 +80,42 @@ await runtime.executeEntrypoint('/src/entry-point.js')
8080
```ts
8181
export interface ViteRuntimeOptions {
8282
/**
83-
* Root of the project
83+
* 项目根目录
8484
*/
8585
root: string
8686
/**
87-
* A method to get the information about the module.
88-
* For SSR, Vite exposes `server.ssrFetchModule` function that you can use here.
89-
* For other runtime use cases, Vite also exposes `fetchModule` from its main entry point.
87+
* 获取模块信息的方法
88+
* 对于 SSRVite 提供了你可以使用的 `server.ssrFetchModule` 函数。
89+
* 对于其他运行时用例,Vite 也从其主入口点提供了 `fetchModule`
9090
*/
9191
fetchModule: FetchFunction
9292
/**
93-
* Configure how source maps are resolved. Prefers `node` if `process.setSourceMapsEnabled` is available.
94-
* Otherwise it will use `prepareStackTrace` by default which overrides `Error.prepareStackTrace` method.
95-
* You can provide an object to configure how file contents and source maps are resolved for files that were not processed by Vite.
93+
* 配置 sourcemap 的解析方式。如果 `process.setSourceMapsEnabled` 可用,优先选择 `node`。
94+
* 否则,默认使用 `prepareStackTrace`,这会覆盖 `Error.prepareStackTrace` 方法。
95+
* 你可以提供一个对象来配置如何解析那些没有被 Vite 处理过的文件的内容和源代码映射。
9696
*/
9797
sourcemapInterceptor?:
9898
| false
9999
| 'node'
100100
| 'prepareStackTrace'
101101
| InterceptorOptions
102102
/**
103-
* Disable HMR or configure HMR options.
103+
* 禁用 HMR 或配置 HMR 选项。
104104
*/
105105
hmr?:
106106
| false
107107
| {
108108
/**
109-
* Configure how HMR communicates between the client and the server.
109+
* 配置 HMR 如何在客户端和服务器之间通信。
110110
*/
111111
connection: HMRRuntimeConnection
112112
/**
113-
* Configure HMR logger.
113+
* 配置 HMR 日志。
114114
*/
115115
logger?: false | HMRLogger
116116
}
117117
/**
118-
* Custom module cache. If not provided, it creates a separate module cache for each ViteRuntime instance.
118+
* 自定义模块缓存。如果未提供,它将为每个 Vite 运行环境实例创建一个独立的模块缓存。
119119
*/
120120
moduleCache?: ModuleCacheMap
121121
}
@@ -128,7 +128,7 @@ export interface ViteRuntimeOptions {
128128
```ts
129129
export interface ViteModuleRunner {
130130
/**
131-
* Run code that was transformed by Vite.
131+
* 运行被 Vite 转换过的代码。
132132
* @param context Function context
133133
* @param code Transformed code
134134
* @param id ID that was used to fetch the module
@@ -139,7 +139,7 @@ export interface ViteModuleRunner {
139139
id: string,
140140
): Promise<any>
141141
/**
142-
* Run externalized module.
142+
* 运行已外部化的模块。
143143
* @param file File URL to the external module
144144
*/
145145
runExternalModule(file: string): Promise<any>
@@ -155,16 +155,16 @@ Vite 默认导出了实现了这个接口的 `ESModulesRunner`。它使用 `new
155155
```ts
156156
export interface HMRRuntimeConnection {
157157
/**
158-
* Checked before sending messages to the client.
158+
* 在向客户端发送消息之前进行检查
159159
*/
160160
isReady(): boolean
161161
/**
162-
* Send message to the client.
162+
* 向客户端发送消息
163163
*/
164164
send(message: string): void
165165
/**
166-
* Configure how HMR is handled when this connection triggers an update.
167-
* This method expects that connection will start listening for HMR updates and call this callback when it's received.
166+
* 配置当此连接触发更新时如何处理 HMR
167+
* 此方法期望连接将开始监听 HMR 更新,并在接收到时调用此回调。
168168
*/
169169
onUpdate(callback: (payload: HMRPayload) => void): void
170170
}
@@ -193,7 +193,7 @@ async function createViteRuntime(
193193
): Promise<ViteRuntime>
194194
```
195195

196-
**Example Usage:**
196+
**使用示例:**
197197

198198
```js
199199
import { createServer } from 'vite'
@@ -219,15 +219,15 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))
219219
export interface MainThreadRuntimeOptions
220220
extends Omit<ViteRuntimeOptions, 'root' | 'fetchModule' | 'hmr'> {
221221
/**
222-
* Disable HMR or configure HMR logger.
222+
* 禁用 HMR 或配置 HMR 日志。
223223
*/
224224
hmr?:
225225
| false
226226
| {
227227
logger?: false | HMRLogger
228228
}
229229
/**
230-
* Provide a custom module runner. This controls how the code is executed.
230+
* 提供自定义模块运行器。这决定了代码的执行方式。
231231
*/
232232
runner?: ViteModuleRunner
233233
}

0 commit comments

Comments
 (0)