Skip to content

Commit 6165168

Browse files
Merge pull request #611 from GODLiangCY/fix/api-plugin
docs: add translations to api-plugin chapter
2 parents cf5f59f + f6d1062 commit 6165168

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

guide/api-plugin.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Vite 插件也可以提供钩子来服务于特定的 Vite 目标。这些钩子
305305

306306
注意 `configureServer` 在运行生产版本时不会被调用,所以其他钩子需要防范它缺失。
307307

308-
### `configurePreviewServer`
308+
### `configurePreviewServer` {#configurepreviewserver}
309309

310310
- **类型:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>`
311311
- **种类:** `async`, `sequential`
@@ -516,17 +516,17 @@ normalizePath('foo\\bar') // 'foo/bar'
516516
normalizePath('foo/bar') // 'foo/bar'
517517
```
518518

519-
## Filtering, include/exclude pattern
519+
## 过滤与 include/exclude 模式 {#filtering-include-exclude-pattern}
520520

521-
Vite exposes [`@rollup/pluginutils`'s `createFilter`](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) function to encourage Vite specific plugins and integrations to use the standard include/exclude filtering pattern, which is also used in Vite core itself.
521+
Vite 暴露了 [`@rollup/pluginutils``createFilter`](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) 函数,以支持 Vite 独有插件和集成使用标准的 include/exclude 过滤模式,Vite 核心自身也正在使用它。
522522

523-
## Client-server Communication
523+
## 客户端与服务端间通信 {#client-server-communication}
524524

525-
Since Vite 2.9, we provide some utilities for plugins to help handle the communication with clients.
525+
Vite 2.9 开始,我们为插件提供了一些实用工具,以帮助处理与客户端的通信。
526526

527-
### Server to Client
527+
### 服务端到客户端 {#server-to-client}
528528

529-
On the plugin side, we could use `server.ws.send` to broadcast events to all the clients:
529+
在插件一侧,我们可以使用 `server.ws.send` 去给所有客户端广播事件:
530530

531531
```js
532532
// vite.config.js
@@ -542,11 +542,11 @@ export default defineConfig({
542542
})
543543
```
544544

545-
::: tip NOTE
546-
We recommend **always prefixing** your event names to avoid collisions with other plugins.
545+
::: tip 注意
546+
我们建议总是给你的事件名称 **添加前缀**,以避免与其他插件冲突。
547547
:::
548548

549-
On the client side, use [`hot.on`](/guide/api-hmr.html#hot-on-event-cb) to listen to the events:
549+
在客户端侧,使用 [`hot.on`](/guide/api-hmr.html#hot-on-event-cb) 去监听事件:
550550

551551
```ts
552552
// client side
@@ -557,9 +557,9 @@ if (import.meta.hot) {
557557
}
558558
```
559559

560-
### Client to Server
560+
### 客户端到服务端 {#client-to-server}
561561

562-
To send events from the client to the server, we can use [`hot.send`](/guide/api-hmr.html#hot-send-event-payload):
562+
为了从客户端向服务端发送事件,我们可以使用 [`hot.send`](/guide/api-hmr.html#hot-send-event-payload)
563563

564564
```ts
565565
// client side
@@ -568,7 +568,7 @@ if (import.meta.hot) {
568568
}
569569
```
570570

571-
Then use `server.ws.on` and listen to the events on the server side:
571+
然后使用 `server.ws.on` 并在服务端监听这些事件:
572572

573573
```js
574574
// vite.config.js

0 commit comments

Comments
 (0)